CEG's Linux User Group

  • Increase font size
  • Default font size
  • Decrease font size
Home Labs Sort list

Sort list

E-mail Print
User Rating: / 9
PoorBest 
Article Index
Sort list
Souce code
Documentation
Test cases & Compatibility
All Pages

SORTING A LIST

Introduction :

The aim of this program is to sort the elements of the list. This is done by considering each element and placing it before an element greater to it. Consider the following list of 3 nodes.

sortlist1

Now, 2 > 3, so it remains as such. Now, 3 < 1, so 3 and 1 are swapped using 2 temporary pointers temp1 and temp2. Another pointer temp is used to traverse through the list till NULL is reached. A pointer 'halt' is made to point the NULL. So, now the list becomes

sortlist2

Now the halt is made to point 3 as it is already sorted. Now 2 and 1 are compared. As 2 > 1, they are swapped. So, now the halt is made to point 2 and finally 1. So, the sorted list is


sortlist3



Last Updated on Saturday, 06 June 2009 19:00  
Please register or login to add your comments to this article.