Vector (ADT)
Jump to navigation
Jump to search
A vector is the simplest indexed data type. It is essentially an abstraction of an array.
Functions
- int size() — Returns how many items are in the vector.
- bool isEmpty() — Returns whether the vector is empty (i.e. size is 0).
- Object elemAtRank(Rank r) — Returns the element stored at rank (similar to [] operator).
- void replaceAtRank(Rank r, Object o) — Puts an object at the specified rank .
- void insertAtRank(Rank r) — Inserts an element at rank and shifts all following items down a rank.
- void removeAtRank(Rank r) — Removes an element from rank and shifts all following items up a rank to fill in the gap.
Implementations
Array-based
- Use an array of actual size , but keep track of true size with an auxiliary variable
- Fixed or growable does not affect the speed
Analysis
best | average | worst | |
---|---|---|---|
elemAtRank | |||
replaceAtRank | |||
insertAtRank | |||
removeAtRank |
[ template ] Abstract Data Types (ADTs) | |
---|---|
Ordered Access to Elements | Stack • Queue • Double-Ended Queue (Deque) |
Random Access to Elements | Vector • List • Sequence |
Key/Value Pairs | Tree • Binary Tree • Priority Queue • Heap • Dictionary • Skip List |
Sorted Storage | Binary Search Tree • AVL Tree • Red-Black Tree |