Hi everyone!
I'm trying to develop a function to sort a linked list. I get no compiling errors, but when I run the program, my program stalls.
Can anyone help?
insert
Code:
struct node* Sort(struct node *head)
{
struct node *original, *current, *pointer, *newList;
original = head;
current = head;
pointer = head;
int smallest = current->data;
int count = 0;
pointer = head;
for(current = head; current != head; current = current->next){
for(pointer = head; pointer != head; pointer = pointer->next){
if(pointer->data < smallest){
smallest = pointer->data;
}
}
while (original->data != smallest){ // count where smallest is in the orignal link list
original = original->next;
count++;
}
newList = AddToList(newList, smallest); // add the smallest value to newList
RemoveFromList(head, count); // remove the smallest value from the original list
count = 0; // reset count
smallest = current->data; // smallest is now the next value in current
}
return newList; // return the newList
}