Advertisement

04.16.2008 at 11:34PM PDT, ID: 23329913
[x]
Attachment Details

Can someone see why i get a seqmentation fault and not the result of the sorted list?

Asked by mezarati in C Programming Language, C++ Programming Language, Algorithms

Tags: Microsoft, C

This program creates a linked list, fills it up with random numbers, sorts it then prints it! i was wandering why im getting a "segmentation fault" when trying to display output!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
#include <stdio.h>
#include <stdlib.h>
 
struct Node {
 int DATA;
 struct Node *Next;
} *Head, *Curr;
 
void List_Init(void);
void Fill_List(struct Node **Add, int Rand);
void Sort_List(void);
void Print_List(void);
 
#define MAX 100
 
int main()
{
List_Init();
Sort_List();
Print_List();
}
 
 
void List_Init(void)
{
struct Node *Add_node = NULL;
 int i = 0; 
 
for(i = 0; i < MAX; i++)
 {
  Fill_List(&Add_node, (rand() % 100));
 }
Head = Add_node;
}
 
void Fill_List(struct Node **Add, int Rand)
{
struct Node *Temp;
Temp = *Add;
 
if (*Add == NULL)
{
*Add = malloc(sizeof(struct Node));
Temp = *Add;
}
 
while (Temp->Next != NULL)
{
Temp = Temp->Next;
Temp->Next = malloc(sizeof(struct Node));
Temp = Temp->Next;
}
Temp->DATA = Rand;
Temp->Next = NULL;
 
 
}
 
void Sort_List(void)
{
int abc;
struct Node* temp;
struct Node* again=Head;
 
while (again)
{
  while(temp->Next)
  {
       if(Head->DATA < temp->DATA)
        {
            abc =  Head->DATA;
          Head->DATA = temp->DATA;
            temp->DATA = abc;
        }
 
       Head = Head->Next;
       temp = temp->Next;
  }
    temp = Head;
  Head = temp->Next;
again=again->Next;
}
 
  //temp=high;
  //temp=head->next;
 
  temp = Head;
 
}
 
void Print_List(void)
{
Curr = Head;
while (Curr != NULL)
{
printf("%d ", Curr->DATA);
Curr=Curr->Next;
}
printf("\n");
}
[+][-]04.16.2008 at 11:50PM PDT, ID: 21374715

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 11:52PM PDT, ID: 21374720

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 11:53PM PDT, ID: 21374724

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 11:56PM PDT, ID: 21374737

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 11:57PM PDT, ID: 21374740

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 11:58PM PDT, ID: 21374743

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.16.2008 at 11:58PM PDT, ID: 21374746

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 12:01AM PDT, ID: 21374756

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 12:15AM PDT, ID: 21374824

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 12:17AM PDT, ID: 21374834

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.17.2008 at 12:46AM PDT, ID: 21374960

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C Programming Language, C++ Programming Language, Algorithms
Tags: Microsoft, C
Sign Up Now!
Solution Provided By: Infinity08
Participating Experts: 5
Solution Grade: A
 
 
[+][-]04.17.2008 at 03:03AM PDT, ID: 21375573

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628