1413 - Queue with delete middle   

Description

Implement a queue of numbers that supports the following operations:

1. print: print the content of the queue, from beginning to end
(use # to specify the end of queue)
2. enqueue: add a number at the end of the queue
3. dequeue: remove a number from the front of the queue
4. delete-mid: remove the item in the middle of the queue, if the
queue has odd number of items. Otherwise, remove the
two items in the middle of the queue if the queue has
even number of items.
(Do nothing when the queue is empty)

Assuming we start with an empty queue, our target is to perform a sequence
of operations specified by the input


Case 1: operations <= 50
Case 2: operations <= 1500
Case 3: operations <= 10000

Input

Each line contains one operation. The input is terminated by end of file. (EOF)

Example Input 1: 

enqueue 1
enqueue 2
print

 

Example Input 2: 

enqueue 1
enqueue 2
enqueue 5
enqueue 4
enqueue 3
delete-mid
print


Example Input 3: 

enqueue 1
enqueue 2
enqueue 5
enqueue 4
enqueue 3
dequeue
delete-mid
print


Example Input 4: 

enqueue 1
enqueue 2
enqueue 5
enqueue 4
enqueue 3
dequeue
dequeue
dequeue
delete-mid
print

Output

For each print operation, print the content of the queue, from beginning to end. Use # to specify the end of queue. Each number and # should be separated by a blank. Note that there is no blank after #. See the Sample Output below.

Example Output 1:

1 2 #


Example Output 2:

1 2 4 3 #


Example Output 3:

2 3 #


Example Output 4:

#

Sample Input  Download

Sample Output  Download

Tags




Discuss