Sorted Linked list Help please
I been ask to create a sorted linked list module, and to test each function with 1 unit, 2 +.
so i wrote my addtofront function( we have to use the same as the teacher)
Code:
struct MyList{
char * name;
Sorted * AddmyChar;
struct MyList * next;
};
typedef struct MyList Sorted;
typedef Sorted * Thelist;
/*the function is this*/
Thelist addfront(Thelist list, Sorted * AddmyChar)
{
Thelist head;
Struct Sorted * temp;
head = AddmyChar;
if(list == NULL){
list = (struct Sorted *)malloc(sizeof(Sorted));
if (list == NULL){
printf("Error! Out of Memory\n");
exit(0);
}
list->head= head;
theList-> next = list;
} else {
temp = list;
while (temp->next != list)
temp = temp->next;
temp-> next = (Sorted *)malloc(sizeof(Sorted));
if(temp -> next == NULL)
{
printf("Error! Out of Memory\n");
exit(0);
}
temp = temp->next;
temp->head = head;
temp->next = list;
}
return (list);
}
}
but i cant seem to test it because it always display a seg fault....
i dont know what i did wrong....how do i call this function in main to display a string i want?