John Mavrick's Garden

Search IconIcon to open search

Last updated April 10, 2022

Status: Tags: #cards/cmpt225/dataStructures Links: Abstract Data Type


List Data Collection

Principles

Implementation

Array-based

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class List {
private:
	static const int INITIAL_SIZE = 5;
	int elements[INITIAL_SIZE];
	// or
	int* elements;
	int elementCount;
	int capacity;
public:
	~List() {
		delete[] elements;
	}
}
### Operations
> capitalized ones are only for pos-oriented, not value
```cpp
// insert an element at a given position in the list
insert(element, POSITION);
// append an element at the end of the list
APPEND(element);
// remove the element at a given position in the list
remove(position);
// remove all the elements from the list
removeAll();
// get the element at a given position in the list
elementType get(position);
// swap two elements
SWAP(position1, position2);
// how many elements are in the list
int getElementCount();

References:

Created:: 2022-03-07 21:13


Interactive Graph