By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,957 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,957 IT Pros & Developers. It's quick & easy.

pls guide me to write a program in c sort a linked list using selection sort

P: 5
pls help me to write a program in c that reads n elements of type float, stores them in a linked list ,sort it in the descending order using selection sort methods, and finally output the sorted linear linked list
Sep 5 '06 #1
Share this Question
Share on Google+
4 Replies


Banfa
Expert Mod 5K+
P: 8,916
You write it and we'll help you debug it.
Sep 5 '06 #2

P: 61
Just write the code using following steps:

1. Start two loops.
2. In the outer loop access all the nodes except the last node.
3. in the inner loop access all nodes the nodes from the node following the node pointed by the variable in the outer loop
4. then check the values and accordingly swap the nodes.
5. go to the next node in the inner loop
6. go to the next node in the outer loop
Sep 6 '06 #3

P: 14
Just write the code using following steps:

1. Start two loops.
2. In the outer loop access all the nodes except the last node.
3. in the inner loop access all nodes the nodes from the node following the node pointed by the variable in the outer loop
4. then check the values and accordingly swap the nodes.
5. go to the next node in the inner loop
6. go to the next node in the outer loop

To add to this one more hint.,

PREVIOUS_NODE;
TEMP_NODE; //
TEMP_NODE->PTR = NEXT_NODE->PTR;
if(CURRENT_NODE->VALUE < NEXT_NODE->VALUE)
{
NEXT_NODE->PTR = PREVIOUS_NODE->PTR;
PREVIOUS_NODE->PTR = CURRENT_NODE->PTR;
CURRENT_NODE->PTR = TEMP_NODE->PTR ;
}




ALL the 4 TEMP_NODE,PREVIOUS_NODE,CURRENT_NODE,NEXT_NODE belong to the same linked list and the rest is just traversal and looping.
Sep 7 '06 #4

P: 1
i need shell,selection,inseration,bubble sorting in linked list please
Nov 27 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.