eolymp
bolt
Try our new interface for solving problems
Problems

Print Linked List

Print Linked List

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 n (1n100). The second line contains n 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.

Time limit 1 second
Memory limit 64 MiB
Input example #1
4
1 2 3 4
Output example #1
1 2 3 4
4 3 2 1
Author Mykhailo Medvediev
Source C++ Language