In this project, we will see how we can implement a stack using an array through a class in C++.
Stacks are abstract data type which means they have a specific order or way to insert/delete & access the elements. Stacks are highly used in system configuration and function calling. Recursion is based on stack function call system.
It’s a function used in the code to push/insert elements in the given stack.
It’s a function used in the code to pop/delete topmost element in the given stack.
It's a function which returns the topmost element from the stack if present. We can only access the topmost element first in stack.
It's a function which will return the number of elements present in the stack.
It's a function which will return a Boolean value to check whether the stack is empty or not.
There are 2 types of constructors in the project 1st is inbuilt constructor where we initialize object without passing any value and another one is a constructor made for giving user option to mention the size of the stack. If while initializing size is not mentioned default size is equal to 4.
1) Stack Object1; = using default constructor so Object1 stack capacity = 4.
2) Stack Object2(10) = using our made constructor here we get a stack of capacity = 10.
1) Initialize the objects/stacks with different capacity.
2) Perform different functions/operations on them.
Submitted by Harsh.Balubhai.Trivedi (Harsh)
Download packets of source code on Coders Packet