Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/khaledashrafh/sqgen
This project demonstrates the use of inheritance, templates and exceptions in C++ to implement two generic data structures: stacks and queues.
https://github.com/khaledashrafh/sqgen
data-structures excep generic-programming object-oriented-programming oob queue stack templates
Last synced: 19 days ago
JSON representation
This project demonstrates the use of inheritance, templates and exceptions in C++ to implement two generic data structures: stacks and queues.
- Host: GitHub
- URL: https://github.com/khaledashrafh/sqgen
- Owner: KhaledAshrafH
- License: mit
- Created: 2021-12-24T22:27:39.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-02T06:08:12.000Z (over 1 year ago)
- Last Synced: 2024-12-07T11:09:05.897Z (19 days ago)
- Topics: data-structures, excep, generic-programming, object-oriented-programming, oob, queue, stack, templates
- Language: C++
- Homepage:
- Size: 7.81 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Generic Stack and Queue Implementation in c++
## Introduction
This project demonstrates the use of inheritance, templates and exceptions in C++ to implement two data structures: stacks and queues. Stacks are based on the LIFO (last in- first out) principle, while queues are based on the FIFO (first in- first out) principle. The project also shows how to make the stack and queue resizable, such that they can store any number of elements of any type.
## Classes
The project consists of four classes and their implementation:
- **Rectangle**: A class that represents a rectangle with length, width and area.
- **MyList**: An abstract class template that stores an array of generic-typed elements with a capacity.
- **MyStack**: A subclass of MyList that implements a stack data structure.
- **MyQueue**: A subclass of MyList that implements a queue data structure.## Main Function
The main function interacts with the user through console input and output. It performs the following steps:
- First, it asks the user whether to use stacks or queues (S/Q).
- Second, it asks whether the user wants to store integers, strings or rectangles (1/2/3).
- Third, it loops for adding elements to the chosen data structure until the user enters N for no more elements.
- Fourth, it displays all the elements stored in the data structure by calling the getElem method until it is empty.The main function also handles exceptions that might occur because of a wrong input from the user.
## How to Run
To run this project, you need to have a C++ compiler installed on your system. You can use any IDE or command-line tool to compile and run the source code files.
Copy
g++ Rectangle.cpp MyList.cpp MyStack.cpp MyQueue.cpp main.cpp -o main ./main