Array
site_name: Array Class Docs
theme:
name: material
nav:
- Home: index.md
📄 docs/index.md¶
# Array Class Documentation
This is a custom implementation of a dynamic array in Python.
---
## Class: `Array`
### Constructor
```python
Array(cap=5)
Initializes the array with a given capacity (default is 5).
- Parameters:
cap(int): Initial capacity of the array. Default is 5.
Method: append(value)¶
Adds a new value at the end of the array.
array.append(value)
- Automatically resizes the array if capacity is exceeded.
Method: pop()¶
Removes and returns the last item.
value = array.pop()
- Raises
IndexErrorif the array is empty.
Method: get(index)¶
Returns the element at the given index.
value = array.get(index)
- Raises
IndexErrorif the index is out of bounds.
Method: last()¶
Returns the last item without removing it.
value = array.last()
- Returns
Noneif the array is empty.
Method: is_empty()¶
Checks if the array is empty.
array.is_empty()
- Returns
Trueif empty, otherwiseFalse.
Internal Method: _resize()¶
Doubles the array's capacity. Used internally by append.
Magic Method: __str__()¶
Returns a string representation of the array (up to current size).
print(array)
🔍 Example Usage¶
arr = Array()
arr.append(1)
arr.append(2)
print(arr.get(1)) # 2
print(arr.pop()) # 2
print(arr.is_empty()) # False
print(arr) # [1]
```
Let me know if you want: - A downloadable ZIP of this project - It hosted on GitHub Pages - To add extra pages (like tests or implementation notes)