| 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...

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....

| < Prev | Next > |
|---|




