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

Recommended Answers

All 2 Replies

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.

Why not sort the list as you insert the node. It will prove to be very easy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.