Translate to Traditional Chinese (δΈ­ζ–‡):


<< Prev   🏠 A B C D    Next >>


C. PAPER QUESTION - QUEUE

Introduction:
The queue is a fundamental data structure based on the concept of First-In-First-Out (FIFO), where the first added element is the first one to be removed and processed
Appending new element in queue is implementing circularly.

Some functions in Queue are described as bellow:

Give the configuration of the list as bellow:

static const int MAX_SIZE = 4; // Capacity of the queue
int data[MAX_SIZE]; // Linearly stores data in a fixed-size array
int size; // Current number of elements in the queue
int front; // Index of the front element, where to take/process the data
int rear; // Index of the rear element, where to add the data

// Default constructor initializes an empty list
Queue() {
size = 0;
front = 0;
rear = -1;
}

Note: The capacity of the queue is MAX_SIZE = 4. If an operation cannot be performed, the queue remains unchanged.

Based on the above configuration and function definitions, complete the table in your question paper:

Id Operators data[] size front rear is_empty() is_full()
0 Queue myQueue = Queue(); [] 0 0 -1 true false
1 myQueue.enqueue(5); [5] 1 0 0 false false
2 myQueue.enqueue(8); [5, 8] 2 0 1 false false
3 myQueue.enqueue(3);
4 myQueue.enqueue(7);
5 myQueue.enqueue(10);
6 myQueue.dequeue();
7 myQueue.enqueue(2);
8 myQueue.enqueue(9);
9 myQueue.peek();
10 myQueue.enqueue(4);
11 myQueue.dequeue();
12 myQueue.enqueue(6);
13 myQueue.dequeue();
14 myQueue.clear();


<< Prev   🏠 A B C D    Next >>