Zig Zag Linked List

easy
1. You are given a linked list with N nodes.
  2. You have to write a function rearrange it such that converted list should
     be of the form a < b > c < d > e < f .. where a, b, c are consecutive data
     node of linked list and such that the order 	  of linked list is sustained.
  3. main takes input from the users and creates the Linked List. You can use
     display to know its contents.
  4. This is a functional problem. 
  5. You should code only the fashion function. It takes as input the
     head of the linked list and rearranges the list in zig zag fashion.
  6. Don't change the code of Node, main and display.

Input Format

First line takes N, the number of elements in the list. Next line takes input N space separated numbers reperesenting elements of the linked list. Input is handled for you.

Output Format

Linked List in zig zag fashion Output is handled for you.

Constraints

1 <= N <= 300

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
5
11 15 20 5 10
Output
11 20 5 15 10
Previous
Swap Pair Elements In Linked List
Next
Next Warmer Day

Related Questions