使用陣列 (array) 寫一個 C++ 佇列 (queue) 類別 (class) 的程式。佇列的主要運算如下:

  1. void enqueue(int):將某個值的元素放入佇列的尾部 (tail),

  2. int dequeue():將佇列頭部 (head) 的元素移出,並回傳該節點的值,

  3. bool is_empty():測試佇列是否為空的。

在主程式中宣告一個佇列物件的變數,並寫一個無限迴圈(infinite loop),選擇並執行下列的指令:

  1. 將某個值的元素放入佇列的尾部,

  2. 將佇列的頭部的元素移出,並印出該元素的值

  3. 測試佇列是否為空的,

  4. 從頭部至尾部列印佇列中所有元素的值

  5. 終止程式執行。

以下為程式執行範例:

****************************************

 

1. Enqueue an element to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

Input command:
1

Input the element being enqueued:
50
 

****************************************


1. Enqueue an elemnet to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

Input command:
1

Input the element being enqueued:
48


****************************************

1. Enqueue an element to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

Input command: 1

Input the element being enqueued:
24

****************************************


1. Enqueue an element to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

Input command:
1

Input the element being enqueued:
60

1. Enqueue an element to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

****************************************


Input command:
4

The queue elements are (from head to tail):
    50
    48
    24
    60

****************************************


1. Enqueue an element to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

Input command:
2

The dequeued element: 50

****************************************


1. Enqueue an element to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

Input command:
3

The queue is not empty.

****************************************


1. Enqueue an element to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

Input command:
4

The queue elements are (from head to tail):
    48
    24
    60

****************************************


1. Enqueue an element to the queue
2. Dequeue an element from the queue
3. Test empty queue
4. Print queue elements
5. Exit the program

Input command:
5