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
pls guide me to write a program in c sort a linked list using selection sort
Collapse
X
-
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 loopComment
-
Originally posted by pukur123Just 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,PREVI OUS_NODE,CURREN T_NODE,NEXT_NOD E belong to the same linked list and the rest is just traversal and looping.Comment
Comment