Maintain a linked list, which supports the following operations:
IH i : Insert head. Insert a new node with integer i to the head of the linked list.
IT i : Insert tail. Insert a new node with integer i to the tail of the linked list.
RH : Remove head. Remove the node at the head of the linked list. (If the linked list is empty, don't do anything.)
RT : Remove tail. Remove the node at the tail of the linked list. (If the linked list is empty, don't do anything.)
S i : Search. Traverse the linked list and find if there exists a node with integer i. If yes, print a line "Y". Otherwise, print a line "N". (If the linked list is empty, print a line "E".)
O : Output. Traverse the linked list from head to tail. Print the integers saved in the nodes sequentially. (If the linked list is empty, print a line "E".)
The first line is an integer n, being the number of operations. Following n lines, each line contains one operation described above.
Restrictions
Note that:
You may reference following structure to construct your linked list.
struct Node
{
int data;
Node *prev;
Node *next;
};
For each "Search" operation and "Output" operation, output one line.
Remember to print a ‘\n’ at the end of the output.
Do not include any spaces at the end of line.