Skip to content

ranjankumar555/cpp-generic-statck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Generic Stack Implementation in C++

A template-based stack implementation in C++ with a user-friendly, menu-driven interface. This project reinforces understanding of stack data structures, type generalization using templates, and basic input validation for secure operations.

✏️ Design

project-2

📌 Project Overview

  • Developed a generic Stack<T> class using C++ templates
  • Interactive CLI to perform stack operations such as:
        push()
        pop()
        top()
        isEmpty()
        size()
  • Fully type-generic: works with user-defined types (int, float, string, etc.)
  • Basic input validation to avoid runtime misuse and simulate boundary cases
  • Clear structure and modular code for ease of maintenance
  • Defensive programming practices: checks for overflow/underflow

🧠 Concepts Applied

  • Data Structures: Stack (LIFO)
  • C++ Templates for generic programming
  • Menu-based console UI using standard I/O
  • Safety checks to prevent invalid operations (e.g., popping from an empty stack)

🛠️ Technologies Used

  • C++ (Templates, OOP)
  • Vi Editor
  • CLI tools and standard library I/O

🧪 Sample Usage

********** Main Menu ***********
-----------------------------------
1. Push Element
2. Pop Element
3. View Top
4. Display Stack
5. Check Empty
6. Stack Size
7. Exit
Select option:
-----------------------------------
Stack<int> intStack;
intStack.push(10);
intStack.push(20);
std::cout << intStack.top();  // Output: 20
intStack.pop();
std::cout << intStack.size(); // Output: 1

📁 Project Structure

.
├── Stack.hpp         # Template class declaration
├── main.cpp          # Menu-driven interface and test driver
└── Makefile          # Build system

This project demonstrates proficiency in C++ templates, OOP, and command-line application development—critical skills for system-level and backend development roles.


Demonstration

Screenshot 2025-05-16 035023

1. Push operation

Screenshot 2025-05-16 035131 Screenshot 2025-05-16 035203

3. Get top element and display stack

Screenshot 2025-05-16 035235

2. Pop operation

Screenshot 2025-05-16 035323

Screenshot 2025-05-16 035346

when user selects wrong option first times it warns, 2nd time also warns to select correct option and in 3rd times it exit from the program so that this avoid potential security issue.

Screenshot 2025-05-16 040111 Screenshot 2025-05-16 040210

About

generic stack to support all data types

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages