Static List Implementations
A static list implementation uses a fixed-size array to store elements, meaning the maximum capacity of the list is determined at the time of creation and cannot be changed dynamically.
Note- Static lists are implemented using arrays, which are contiguous blocks of memory.
- This makes accessing elements by index very fast.
Static lists are ideal for scenarios where the number of elements is known in advance and does not change frequently.
Example- Fixed-size buffers in networking.
- Predefined datasets in embedded systems.
- Lookup tables in games or simulations.
Key Methods in Static Lists
- listEmpty: Checks if the list is empty.
- listFull: Checks if the list is full.
- addHead: Adds an element to the beginning of the list.
- addTail: Adds an element to the end of the list.
- insert: Inserts an element at a specified position.
- delete: Removes an element from a specified position.
Let's examine each method in detail.
ExampleFor examples, we will use IB pseudocode with variables such as:
- MAX - maximum number of elements
- SIZE - how many elements are in the list currently
- LIST - array of length MAX
Checking List Status
listEmpty: This method checks if the list is empty by verifying that its size is zero.
Examplemethod listEmpty()
return SIZE = 0
end methodlistFull: This method checks if the list is full by comparing the list's size to its maximum capacity.
Examplemethod listFull
return SIZE = MAX
end method