CEG's Linux User Group

  • Increase font size
  • Default font size
  • Decrease font size
Home Labs Reversing a List

Reversing a List

E-mail Print
User Rating: / 2
PoorBest 
Article Index
Reversing a List
source code
documentaion
Test cases & compatibility
All Pages

REVERSING A LIST


INTRODUCTION:

The objective of 'Reversing a List' program is to place the elements in the list in the reverse order.

For instance, consider a list having three nodes...

node


In the source code, the temporary variables 'temp1' and 'temp2' are used to swap two elements in the list. The pointer 'temp' is used to traverse through the list till NULL is reached. Initally 'halt' is assigned to NULL.

When the 'reverse' function is called , initially 'loop 1'(mentioned in the code)is executed to make sure that the list is not empty as 'halt' is assigned to NULL initially. The 'loop 2' (mentioned in the code)in source code checks for the condition and accordingly the swapping is done. Once the control is out of 'loop 2' , 'halt' is reassigned and the control goes back to 'loop 1'.

And the swapping goes like in steps as shown in the following figures....

revlist4




Last Updated on Tuesday, 09 June 2009 12:50  
Please register or login to add your comments to this article.