Given a single linked list write a function to swap each pair of nodes by manipulating with pointers (not values
). If last element does not have a pair, then leave it as is.
For example:
Original list: head->1->2->3->4->5->NIL should be transformed to head->2->1->4->3->5-> NIL
Optimization note: this algorithm can be implemented with one cycle and without IF statements.
Good luck!