Tag Archives: linked list

Swap alternate nodes in a singly linked list

Given a single Linked List. Swap every other alternate nodes. For example, given 1–>2–>3–>4–>5–>null then output 3–>4–>5–>2–>1–>null. Note that, the list was transformed in several steps. First step, swap 1 and 3 i.e. 3–>2–>1–>4–>5–>null Second step, swap 2 and 4 i.e. 3–>4–>1–>2–>5–>null last step, swap 1 and 5, i.e. 3–>4–>5–>2–>1–>null We can observe that, each […]