Basic Operations on Stack in C++

Following are some basic operations in the stack that make it easy to manipulate the stack data structure:

Operation

Description

Time Complexity

Space Complexity

Push

Add the element to the top of the stack.

O(1)

O(1)

Pop

Remove the element on the top of the stack.

O(1)

O(1)

Peek

Returns the element at the top of the stack without removing it.

O(1)

O(1)

IsEmpty

Checks if the stack is empty.

O(1)

O(1)

Stack implementation in C++

Stack is the fundamental data structures used in the computer science to the store collections of the objects. It can operates on the Last In, First Out (LIFO) principle where the most recently added the object is the first one to be removed. It can makes the stacks highly useful in the situations where you to the reverse a series of the operations or repeatedly undo operations.

In this article, we will learn how to implement the stack data structure in C++ along with the basic stack operations.

Similar Reads

Stack Data Structure in C++

A stack can be visualized as the vertical stack of the elements, similar to the stack of the plates. We can only add or remove the top plate. Similarly, in the stack data structures, elements can added to and removed from the top of the stack....

Basic Operations on Stack in C++

Following are some basic operations in the stack that make it easy to manipulate the stack data structure:...

C++ Program for the Implementation of Stack

This example that implements the stack using arrays and demonstrates the basic stack operations:...

Applications of the Stack in C++

It can applies on the Expression Evaluation and it can evaluates the prefix, postfix and infix expressions.It can applies on the Function calls and recursion.It can applies in text editors for undo mechanisms functionalities.It can applies on syntax parsing and syntax checking....