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


<< Prev   🏠 A B C D    Next >>


B. PAPER QUESTION - STACK

Introduction:
The stack is a fundamental data structure based on the concept of Last-In-First-Out (LIFO), where the last added element is the first one to be removed and processed.

Some functions in Stack are described as bellow:

Give the configuration of the stack as bellow:

static const int MAX_SIZE = 4; // Capacity of the stack
int data[MAX_SIZE]; // Linearly stores data in a fixed-size
array int size; // Current number of elements in the
array // Default constructor initializes an empty stack
List() {
size = 0;
}

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

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

Id Operators data[] size is_empty() is_full()
0 Stack myStack = Stack(); [] 0 true false
1 myStack.push(5) [5] 1 false false
2 myStack.push(8) [5, 8] 2 false false
3 myStack.push(3)
4 myStack.push(7)
5 myStack.push(10)
6 myStack.pop()
7 myStack.push(2)
8 myStack.top()
9 myStack.push(9)
10 myStack.top()
11 myStack.push(4)
12 myStack.pop()
13 myStack.clear()


<< Prev   🏠 A B C D    Next >>