Coders Packet

Class Stack implemented through array class in C++

By Harsh.Balubhai.Trivedi

In this project, we will see how we can implement a stack using an array through a class in C++.

Stack 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.


1)Push ():

           It’s a function used in the code to push/insert elements in the given stack.

2)Pop ():

          It’s a function used in the code to pop/delete topmost element in the given stack.

3)Top ():

         It's a function which returns the topmost element from the stack if present. We can only access the topmost element first in stack.

4)Size ():

        It's a function which will return the number of elements present in the stack.

5)Is-Empty ():

        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.





Download project

Reviews Report

Submitted by Harsh.Balubhai.Trivedi (Harsh)

Download packets of source code on Coders Packet