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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaveta
    New Member
    • Aug 2006
    • 5

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

    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
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You write it and we'll help you debug it.

    Comment

    • pukur123
      New Member
      • Sep 2006
      • 61

      #3
      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

      Comment

      • Rakesh Mutharaju
        New Member
        • Sep 2006
        • 14

        #4
        Originally posted by pukur123
        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,PREVI OUS_NODE,CURREN T_NODE,NEXT_NOD E belong to the same linked list and the rest is just traversal and looping.

        Comment

        • duaa
          New Member
          • Nov 2006
          • 1

          #5
          i need shell,selection ,inseration,bub ble sorting in linked list please

          Comment

          Working...