Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (anonymous):

Sorting Linked List in C or C++ in order

OpenStudy (anonymous):

void sort (){ node* forth = NULL; for (node* i = head; i->link != nullptr; i = i->link ){ for (node* j = i->link; j != nullptr; j = j->link){ if ( i->data > j->data ){ forth = i; i = j->link; j->link = forth; } } } }

OpenStudy (anonymous):

i have that but it is not working any help would be appreciable

OpenStudy (anonymous):

Your code doesn't make sense. If you are at the 3rd element, and you decide you need to swap it with the 7th element: The 2nd element must now point at the 7th. The 6th element must now point at the 3rd. The 3rd element must now point at the 8th. The 7th element must now point at the 4th.

OpenStudy (anonymous):

Create a function that allows you to swap elements, then after that you can do sorting this way.

OpenStudy (anonymous):

A much better way is to create an array, put the linked list items in the array, sort that array, then change all the links based on that array.

OpenStudy (anonymous):

i am not suppose to use arrays for the assignment

OpenStudy (anonymous):

Then you need to understand how to use linked lists properly.

OpenStudy (anonymous):

new to linked list. still trying to grasp the whole concept of linked lists

OpenStudy (anonymous):

draw a picture with all the links.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!