Sequence (ADT)
Jump to navigation
Jump to search
A sequence, according to the textbook is "a union between a vector and a list." It mentions two functions used to convert between ranks and positions, but nothing else.
This page is my interpretation of what the book said.
A sequence has access to elements by both rank and position.
Functions
Standard ADT Methods:
- int size() — Returns how many items are in the list.
- bool isEmpty() — Returns whether the list is empty (i.e. size is 0).
"Bridge" Methods:
- Rank rankOf(Position p) — Returns the corresponding rank of the given position Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle p} .
- Position positionOf(Rank r) — Returns the corresponding position of the given rank Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle r} .
Methods from List:
- bool isFirst(Position p) — Returns whether the specified position is the first item in the list.
- bool isLast(Position p) — Returns whether the specified position is the last item in the list.
- Position first() — Returns the position of the first item in the list.
- Position last() — Returns the position of the last item in the list.
- Position before(Position p) — Returns the position of the element prior to Position .
- Position after(Position p) — Returns the position of the element after Position .
- void replaceElement(Position p, Object o) — Replaces the element at position with an object .
- void swapElements(Position p, Position q) — Switches the element stored at position Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle p} with the one from position Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle q} and vice versa.
- Position insertBefore(Position p, Object o) — Inserts a new element Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle o} before position Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle p} and returns the position of the newly inserted element.
- Position insertAfter(Position p, Object o) — Inserts a new element Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle o} after position Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle p} and returns the position of the newly inserted element.
- Position insertFirst(Object o) — Inserts a new element Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle o} at the beginning of the list and returns the position of the newly inserted element.
- Position insertLast(Object o) — Inserts a new element Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle o} at the end of the list and returns the position of the newly inserted element.
- void remove(Position p) — Removes an object from Position Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle p} .
Methods from Vector:
- Object elemAtRank(Rank r) — Returns the element stored at rank Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle r} (similar to [] operator).
- void replaceAtRank(Rank r, Object o) — Puts an object Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle o} at the specified rank Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle r} .
- void insertAtRank(Rank r) — Inserts an element at rank Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle r} and shifts all following items down a rank.
- void removeAtRank(Rank r) — Removes an element from rank Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle r} and shifts all following items up a rank to fill in the gap.
| [ 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 |