Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/jdsherbert/simple-stack-implementation

Simple C++ Stack class template using a custom Node structure to behave like a linked list structure.
https://github.com/jdsherbert/simple-stack-implementation

boilerplate boilerplate-template cpp cpp11 cpp14 cpp17 cpp20 generic list reference stack stackoperation stackoperations

Last synced: about 18 hours ago
JSON representation

Simple C++ Stack class template using a custom Node structure to behave like a linked list structure.

Awesome Lists containing this project

README

        

![image](https://github.com/JDSherbert/Threadsafe-Singleton-Class/assets/43964243/8a288a74-0a1e-4fcb-a5d8-608bb7c9d46b)

# Simple Stack Implementation


Stars Badge
Forks Badge
Watchers Badge
Issues Badge

-----------------------------------------------------------------------


C++ Template



License



-----------------------------------------------------------------------
## Overview
You can use this Stack class with different types, such as int, double, std::string, or custom types, by specifying the desired type `` when creating an instance of the stack.
```
// Example usage of this stack
Stack intStack;
intStack.push(69);
intStack.push(420);

std::cout << "Size of the stack: " << intStack.size() << std::endl;
std::cout << "Top element: " << intStack.peek() << std::endl;

intStack.pop();
std::cout << "After pop, size of the stack: " << intStack.size() << std::endl;
```

This version of a Stack class uses a linked list with a custom Node structure instead of relying on `std::list` or `std::vector`. The push, pop, peek, isEmpty, and size functions operate on this linked list. The Node structure represents each element in the stack, and the next pointer links the elements together in the stack.

-----------------------------------------------------------------------