https://github.com/chihebabiza/my-cpp-stack-array
A lightweight, template-based stack class built on top of the `clsMyQueueArr` class, which in turn uses a custom dynamic array (`clsDynamicArray`). This class provides basic stack behavior (LIFO โ Last In, First Out) by inserting new elements at the beginning of the internal array.
https://github.com/chihebabiza/my-cpp-stack-array
cpp cpp-library data-structures oop stack
Last synced: 5 months ago
JSON representation
A lightweight, template-based stack class built on top of the `clsMyQueueArr` class, which in turn uses a custom dynamic array (`clsDynamicArray`). This class provides basic stack behavior (LIFO โ Last In, First Out) by inserting new elements at the beginning of the internal array.
- Host: GitHub
- URL: https://github.com/chihebabiza/my-cpp-stack-array
- Owner: chihebabiza
- License: mit
- Created: 2025-06-19T12:54:47.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2025-06-19T13:05:11.000Z (6 months ago)
- Last Synced: 2025-06-19T14:19:30.162Z (6 months ago)
- Topics: cpp, cpp-library, data-structures, oop, stack
- Language: C++
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stack Implementation Using Dynamic Array in C++
A lightweight, template-based stack class built on top of the `clsMyQueueArr` class, which in turn uses a custom dynamic array (`clsDynamicArray`). This class provides basic stack behavior (LIFO โ Last In, First Out) by inserting new elements at the beginning of the internal array.
---
## ๐ฆ Features
- LIFO stack behavior
- Uses custom queue and dynamic array as a base
- Supports viewing the top and bottom of the stack
- Easy integration and extensibility
---
## ๐งช Example Usage
```cpp
#include
#include "clsMyStackArr.h"
int main() {
clsMyStackArr myStack;
myStack.push(100);
myStack.push(200);
myStack.push(300);
std::cout << "Top: " << myStack.Top() << std::endl; // 300
std::cout << "Bottom: " << myStack.Bottom() << std::endl; // 100
// Since this extends clsMyQueueArr, you can also access other methods like:
myStack.Print(); // Output: 300 200 100
}
````
---
## ๐งฐ Public Methods
| Method | Description |
| ------------- | ----------------------------------------------- |
| `push(value)` | Pushes a new item onto the top of the stack |
| `Top()` | Returns the item at the top of the stack |
| `Bottom()` | Returns the item at the bottom (oldest element) |
| `Print()` | Inherited โ prints all items in stack order |
| `Size()` | Inherited โ returns number of items |
| `IsEmpty()` | Inherited โ checks if stack is empty |
| `Clear()` | Inherited โ clears all items |
| `Reverse()` | Inherited โ reverses the stack order |
---
## ๐งฑ Inheritance Structure
```
clsDynamicArray
โ
clsMyQueueArr
โ
clsMyStackArr
```
Each layer adds additional functionality:
* `clsDynamicArray` handles raw dynamic array operations.
* `clsMyQueueArr` implements queue logic using `clsDynamicArray`.
* `clsMyStackArr` overrides `push()` to behave like a stack.
---
## ๐ Use Case
Perfect for:
* Learning inheritance in C++
* Understanding how stacks and queues can be built on top of arrays
* Educational demos and exercises
---
## ๐ง Dependencies
* `clsDynamicArray.h`
* `clsMyQueueArr.h`
Include all related `.h` files and then import `clsMyStackArr.h` in your main project.
---
## ๐งพ License
This project is licensed under the MIT License. See [LICENSE](LICENSE) for full details.