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 data
The first line contains number n (1 ≤ n ≤ 100). The second line contains n integers.
Output data
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
4 1 2 3 4
1 2 3 4 4 3 2 1