Reorder List
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 64 megabytes
Given an array of integers. Create a Linked List from these numbers.
Write a method ReorderList
that reorders a list L[0]
→ L[1]
→ L[2]
→ ... → L[n-1]
→ L[n]
into L[0]
→ L[n]
→ L[1]
→ L[n-1]
→ L[2]
→ L[n-2]
→ ... .
Write the code according to the next interface:
class Node { public: int data; Node *next; Node() : next(NULL) {}; Node(int data, Node *next = NULL) : data(data), next(next) {}; }; class List { public: Node *head, *tail; List() : head(NULL), tail(NULL) {}; void addToTail(int val); // Add number val to the end of the Linked List void ReorderList(void); // Reorder a list as given above void Print(void); // Print the elements of Linked List };
You can create (use) additional methods if needed.
Input
The first line contains number n (1 ≤ n ≤ 10000). The second line contains n integers.
Output
Print the elements of reordered Linked List using Print method.
Examples
Input #1
Answer #1
Submissions 903
Acceptance rate 56%