Sequential List¶
Interface¶
Implement a linear list sequentially.
- class SeqList(MAXSIZE: int = 10)¶
Linear list implemented with sequential storage
- __init__(MAXSIZE: int = 10) None¶
Initialize an empty sequential list.
- Parameters:
MAXSIZE – Determines the max size of the squential list. Optional, defaults to 10 if not provided.
- Variables:
data – A list stores all of the data.
last – The position of the last value in the list.
- len() int¶
Calculate the length of the list.
Time complexity is \(O(1)\).
- Returns:
Return the amount of the elements within the list.
- index(index: int) int¶
Find the first encountered element by its index.
Time complexity is \(O(1)\).
- Parameters:
index – The specified index of the target element.
- Returns:
The elment of the given index.
- element(element: int, start_index: int = 0) int¶
Find the index of the specified element encountered first time.
Time complexity is \(O(n)\).
- Parameters:
element – The specified element you want to find.
start_index – The specified index from which you want to start finding the element. Optional, defaults to 0 if not provided.
- Returns:
The index of the given element. If the return value is -1 ,it means the given element was not found.
- insert(element: int, index: int) None¶
Insert the specified element into the list of the specified index.
Time complexity is \(O(n)\).
- Parameters:
element – Specify the element to be inserted.
index – Specify the index to be inserted.
- delete(index: int) None¶
Delete the element from the list .
Time complexity is \(O(n)\).
- Parameters:
index – Specify the index to be delete.
- class SeqDualStack(MAXSIZE: int = 10)¶
Dual stack implemented with sequential list.
- __init__(MAXSIZE: int = 10) None¶
Initialize an empty sequential double stack.
- Parameters:
MAXSIZE
- Variables:
data – A list stores all of the data.
top_0 – The pointer to the top of the stack 0.
top_1 – The pointer to the top of the stack 1.
- push(item: int, tag: int = 0) None¶
Push the given item into the stack.
- Parameters:
item – Specify the item to be pushed
tag – Indicate the stack into which the item will be pushed
- pop(tag: int = 0) int¶
Pop the item from the stack top.
- Parameters:
tag – Indicate the stack into which the item will be poped
- class SeqQueue(MAXSIZE: int = 10)¶
Queue implemented with sequential storage.
- __init__(MAXSIZE: int = 10) None¶
Initialize an empty queue.
- Parameters:
MAXSIZE – The max size of the queue.
- Variables:
data – A list stroes all of the data.
fromt – The pointer to the front of the queue.
rear – The pointer to the rear of the queue.
- add(item: int) None¶
Add the specifed item into the queue.
- Parameters:
item – The item to be added into queue.
- delete() int¶
Delete the item from the queue.
- Returns:
The item to be deleted from the queue.