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


<< Prev   🏠 A B C D    Next >>


A. PAPER QUESTION - LIST

Introduction:
A list is a basic data structure that stores elements in a linear order. Unlike arrays, lists can dynamically grow or shrink in size, and elements can be inserted or removed at any position. The elements in a list are stored sequentially, and each element can be accessed directly by its position or index

Some functions in List are described as bellow:

Give the configuration of the list as bellow:

static const int MAX_SIZE = 4; // Capacity of the list
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 list
List() {
size = 0;
}

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

Based on the above configuration and function definitions, complete the table below
The table has been completed and is provided below for your reference

Id Operators data[] size front() back() is_full()
0 List myList = List(); [] 0 -1 -1 false
1 myList.append(1) [1] 1 1 1 false
2 myList.append(3) [1, 3] 2 1 3 false
3 myList.append(5) [1, 3, 5] 3 1 5 false
4 myList.append(7) [1, 3, 5, 7] 4 1 9 true
5 myList.append(9) [1, 3, 5, 7] 4 1 7 true
6 myList.remove(2) [1, 3, 7] 3 1 7 false
7 myList.erase(7) [1, 3] 2 1 3 false
8 myList.erase(4) [1, 3] 2 1 3 false
9 myList.clear() [] 0 -1 -1 false
Now it's your turn! Complete the table in your question paper:
Id Operators data[] size front() back() is_full()
0 List myList = List(); [] 0 -1 -1 false
1 myList.append(4)
2 myList.append(9)
3 myList.append(2)
4 myList.append(7)
5 myList.append(5)
6 myList.insert(1, 8)
7 myList.remove(3)
8 myList.erase(7)
9 myList.append(6)
10 myList.insert(2, 3)
11 myList.clear()


<< Prev   🏠 A B C D    Next >>