How to print the reverse order of nodes in a link list
An implementation in C would be something as:
typedef struct node
struct node *next;
- void print(node *head)
- node *move, *n1;
- if(move==NULL) return;
In the outer loop, MOVE is initialized to HEAD and n1 to NULL. After the inner loop ends, MOVE will point to the last element. We print its value. Then the pointer N1 is set to point to the last element. In the next iteration of the outer loop, MOVE is again set to HEAD and MOVE moves till it advances to the second last node. Then we print its value and set N1 to the second last element. It continues till we reach the HEAD.