Stack ADT in Data Structures

The abstract datatype is special kind of datatype, whose behavior is defined by a set of values and set of operations. The keyword “Abstract” is used as we can use these datatypes, we can perform different operations. But how those operations are working that is totally hidden from the user. The ADT is made of with primitive datatypes, but operation logics are hidden.

Here we will see the stack ADT. These are few operations or functions of the Stack ADT.

  • isFull(), This is used to check whether stack is full or not
  • isEmpry(), This is used to check whether stack is empty or not
  • push(x), This is used to push x into the stack
  • pop(), This is used to delete one element from top of the stack
  • peek(), This is used to get the top most element of the stack
  • size(), this function is used to get number of elements present into the stack


 Live Demo

using namespace std;
   stack<int> stk;
      cout << "Stack is empty" << endl;
   } else {
      cout << "Stack is not empty" << endl;
   //insert elements into stack
   cout << "Size of the stack: " << stk.size() << endl;
   //pop and dispay elements
      int item =; // same as peek operation
      cout << item << " ";


Stack is empty
Size of the stack: 5
50 40 30 20 10

Updated on: 27-Aug-2019

18K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started