https://github.com/taharachedi/custom_stackarr_library-cpp
Not a standard stackβit's a unique implementation built on a custom queue array, supporting push, pop, top, bottom, reversal, and element modifications.
https://github.com/taharachedi/custom_stackarr_library-cpp
datastructures-algorithms stack
Last synced: 3 months ago
JSON representation
Not a standard stackβit's a unique implementation built on a custom queue array, supporting push, pop, top, bottom, reversal, and element modifications.
- Host: GitHub
- URL: https://github.com/taharachedi/custom_stackarr_library-cpp
- Owner: taharachedi
- Created: 2025-03-07T12:11:57.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-03-07T12:13:45.000Z (4 months ago)
- Last Synced: 2025-03-07T13:24:03.387Z (4 months ago)
- Topics: datastructures-algorithms, stack
- Language: C++
- Homepage:
- Size: 726 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π Stack Implementation (clsMyStackArr) β‘
> **A C++ template-based stack implementation using a dynamic array (`clsDynamicArray`), supporting fundamental stack operations along with extended functionalities. π**
---
## π Project Overview
The `clsMyStackArr` class provides a **generic stack** implementation in C++, leveraging the `clsMyQueueArr` class for efficient memory management and stack operations. It supports essential operations like **push**, **pop**, **peek top & bottom**, and additional functionalities for dynamic stack modifications.
### πΉ Core Functionalities:
- **Push & Pop Operations** π
- **Access Top & Bottom Elements** π
- **Check Stack Size & Emptiness** π
- **Reverse Stack Elements** π
- **Modify & Insert Elements Within Stack** βοΈ
- **Clear the Stack in One Call** β¨This stack implementation is **generic**, meaning it can store any data type using C++ templates.
---
## β¨ Features
### πΉ Basic Stack Operations
- **`Push(Value)`**: Adds an element to the top of the stack.
- **`Pop()`**: Removes the top element from the stack.
- **`Top()`**: Retrieves the top element of the stack.
- **`Bottom()`**: Retrieves the last element of the stack.
- **`Size()`**: Returns the number of elements in the stack.
- **`IsEmpty()`**: Checks if the stack is empty.
- **`Print()`**: Displays the stack elements.### πΉ Extended Functionalities
- **`GetItem(Index)`**: Retrieves the value at a specific index.
- **`Reverse()`**: Reverses the order of stack elements.
- **`UpdateItem(Index, NewValue)`**: Updates the value at a given index.
- **`InsertAfter(Index, Value)`**: Inserts an element after a specified index.
- **`InsertAtFront(Value)`**: Inserts an element at the top of the stack.
- **`InsertAtBack(Value)`**: Inserts an element at the bottom of the stack.
- **`Clear()`**: Removes all elements from the stack.---
## π How It Works
### πΉ Push & Pop
- Elements are added using `Push(Value)` at the **top** of the stack.
- Elements are removed using `Pop()` from the **top**.### πΉ Accessing Elements
- `Top()` and `Bottom()` allow **direct access** to the first and last elements.
- `GetItem(Index)` retrieves an element at a specific position.### πΉ Modifications & Reversal
- `UpdateItem(Index, NewValue)` modifies an existing value.
- `Reverse()` swaps element positions to **reverse** the stack order.
- `InsertAfter(Index, Value)`, `InsertAtFront(Value)`, and `InsertAtBack(Value)` allow **custom insertions**.### πΉ Memory Management
- The stack dynamically allocates memory for new elements.
- `Clear()` safely removes all elements to prevent memory leaks.---
## π Potential Enhancements
- π **Iterator Support**: Implementing iterators for STL-like traversal.
- β³ **Time Complexity Optimization**: Enhancing performance for large datasets.
- ποΈ **Persistent Storage**: Implementing file handling for saving stack data.
- π **Thread Safety**: Making the stack thread-safe for concurrent operations.---
## βοΈ Technologies Used
- **Language**: C++
- **Templates**: Enables the stack to store any data type.
- **Dynamic Array-based Stack**: Uses `clsDynamicArray` for flexible data storage.
- **Memory Management**: Utilizes dynamic memory allocation.---
## π― Learning Outcomes
This project demonstrates:
- β **Stack operations (push, pop, top, bottom, size, empty check)**
- β **Generic programming with C++ templates**
- β **Efficient memory management with dynamic arrays**
- β **Advanced stack modifications (insertion, reversal, updating)**---
## π License
This project is **open-source**. Feel free to modify and enhance it! π
---
## π€ Contributing
Contributions are welcome! If you have ideas for improvements, submit a Pull Request.
---
## π Ready to Explore?
### π How to Run
1. **Download** the repository.
2. **Include** `clsMyStackArr.h` in your project.
3. **Compile & Run** your C++ program with a standard compiler (e.g., `g++ main.cpp -o output`).
4. **Test** different stack operations.