A reusable Generic Stack and Generic Queue implementation in C++ using Templates and Singly Linked Lists.
This project demonstrates how to build reusable data structures that work with multiple data types such as int, float, double, char, and string.
- ✅ Generic Programming using C++ Templates
- ✅ Stack (LIFO) Implementation
- ✅ Queue (FIFO) Implementation
- ✅ Singly Linked List Based
- ✅ Dynamic Memory Allocation
- ✅ Easy to Reuse in Other Projects
DataStructures/
│
├── DataStructures.h # Master header file (includes all data structures)
├── Main.cpp # Example program to test the library
│
├── Stack.cpp # Generic Stack implementation
├── Queue.cpp # Generic Queue implementation
│
├── SinglyLinearGeneric.cpp # Generic Singly Linear Linked List
├── SinglyCircularGeneric.cpp # Generic Singly Circular Linked List
├── DoublyLinearGeneric.cpp # Generic Doubly Linear Linked List
└── DoublyCircularGeneric.cpp # Generic Doubly Circular Linked List
| Function | Description |
|---|---|
push() |
Insert an element |
pop() |
Remove and return the top element |
peep() |
View the top element |
Display() |
Display all elements |
Count() |
Return total elements |
| Function | Description |
|---|---|
enqueue() |
Insert an element at the rear |
dequeue() |
Remove and return the front element |
Display() |
Display all elements |
Count() |
Return total elements |
Include the header file
#include "DataStructures.h"Stack<int> s;
s.push(10);
s.push(20);
s.push(30);
s.Display();
cout << "Top Element : " << s.peep() << endl;
cout << "Removed : " << s.pop() << endl;Queue<int> q;
q.enqueue(100);
q.enqueue(200);
q.enqueue(300);
q.Display();
cout << "Removed : " << q.dequeue() << endl;Stack<int>
Stack<float>
Stack<double>
Stack<char>
Stack<string>
Queue<int>
Queue<float>
Queue<double>
Queue<char>
Queue<string>| Operation | Complexity |
|---|---|
| Push | O(1) |
| Pop | O(1) |
| Peep | O(1) |
| Display | O(n) |
| Count | O(1) |
| Operation | Complexity |
|---|---|
| Enqueue | O(1) |
| Dequeue | O(1) |
| Display | O(n) |
| Count | O(1) |
Compile using g++
g++ main.cpp -o appRun
app.exe./appStack Elements:
| 30 |
| 20 |
| 10 |
Top Element : 30
Removed : 30
Queue Elements:
| 100 | - | 200 | - | 300 |
Removed : 100
- Add Destructor
- Exception Handling
- Copy Constructor
- Move Constructor
- Assignment Operator
- Iterator Support
- STL-style Interface
- C++ Templates
- Generic Programming
- Singly Linked List
- Dynamic Memory Allocation
- Object-Oriented Programming (OOP)
Yogiraj Khaladkar
Engineering Student | C++ | Data Structures & Algorithms
⭐ If you found this project helpful, consider giving it a Star on GitHub!