I have struct which is like this

struct Node
     int Num;
     Node *Point

so the program has to insert the numbers in the list during the execution, so the user can insert as many number as s/he wants so I want to sort those numbers when printing, I have a function call printList(Node *Current) so I need help on how to sort this I have tried selection sort but that didnt work out, I cant understant how am I gona relate the pointer variable which is Current with the sorting of the numbers in memory location

9 Years
Discussion Span
Last Post by Prabakar

You should have a separate function to sort the linked list.

Selection sort should be fine, what didnt work out?
Have a node call LowestNode and have equal to the head of the list and iterate comparing if its smaller then that node becomes the lowest and if it reaches the end, append it to the new linked list and start the whole procedure again till you reach the end of your current linked list and your new linked list should be sorted.

so your printList is easier to implement
your printList(Node* Current), current will be the head of the list, so you just iterate from head to the end printing the num.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.