Print Linked List#7452

Print Linked List

1 second
64 megabytes
Very easy

Given an array of integers. Create a Linked List from these numbers. Print a Linked List in normal and in reverse direction.

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 Print(void); // Print the elements of Linked List
    void PrintReverse(void); // Print the elements of Linked List in reverse order
};

You can create (use) additional methods if needed.

Input

The first line contains number (1 \leq n \leq 100). The second line contains integers.

Output

Print in the first line the elements of Linked List using Print method. Print in the second line the elements of Linked List in reverse order using PrintReverse method.

Examples

Example 1

Loading
Loading