An open API service indexing awesome lists of open source software.

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.

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.