Sequential List¶
Source code: src/pydsadoc/_linear/seque.py
- class SeqList(maxsize: int = 16, /, *args, **kwargs)¶
Implement a linear list sequentially.
- __str__() str¶
Implement built-in function
print().Treaverse the linked list. The time complexity is \(O(n)\).
- index(value: None | int, start: int = 0, stop: int = 9223372036854775807, /) int¶
Return first index of the value.
At or after index start and before index stop. Time complexity is \(O(n)\).
- insert(index: int, obj: None | int, /) None¶
Insert object before index.
Time complexity is \(O(n)\).
Stack
A stack can be implemented with a sequential list SeqList and its
methods SeqList.append() and SeqList.pop() as described
above. Specifically, the stack.append(object) and stack.pop()
operations.
Notably, in this case, the time complexity of these two methods is \(O(1)\).
Queue
A queue can be implemented with a sequential list SeqList and its
methods SeqList.append() and SeqList.pop() as described
above. Specifically, the queue.append(object) and queue.pop(0)
operations.
Notably, in this case, the time complexity of the method
SeqList.append() is \(O(1)\), but of the method
SeqList.pop() is \(O(n)\).