Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

What is Stack Data Structure?

Stack is an abstract data type with a bounded (predefined) capacity. It is a simple data structure
that allows adding and removing elements in a particular order. Every time an element is added,
it goes on the top of the stack and the only element that can be removed is the element that is at
the top of the stack, just like a pile of objects.
An Abstract Data Type (ADT) used in the programming languages is known as a Stack. As the
name implies it works as a real stack like a deck of cards or pile of plates.

A real-world stack allows operations at one end only. For instance, a card or plate can be placed
or removed from the top of the stack only. Even Stack ADT allows the data operations at only on
end. Only the top element of a stack can be accessed at any time.
This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. The element placed
last is accessed first. In Stack, operation is called PUSH operation and removal operation is
called POP operation.
How Data Structure Stack is represented?
What are the basic operations supported by Stack?
The operations supported by stack involve initializing of the stack, de-initializing. Apart from
these, the other operations supported by Stack are:
 push() − Pushing (storing) an element on the stack.
 pop() − Removing (accessing) an element from the stack.
By checking the status of the stack, the stack is used efficiently for which some of the functions
are added to the stacks:
 peek() − get the top data element of the stack, without removing it.
 isFull() − check if stack is full.
 isEmpty() − check if stack is empty.
At all times, a pointer is maintained to the last PUSHed data on the stack. As this pointer always
represents the top of the stack, hence named top. The top pointer provides top value of the stack
without actually removing it.
What are the steps involved in a Stack Push Operation?
The process of putting a new data element onto stack is known as a Push Operation. Push
operation involves a series of steps −
 Step 1 − Checks if the stack is full.
 Step 2 − If the stack is full, produces an error and exit.
 Step 3 − If the stack is not full, increments top to point next empty space.
 Step 4 − Adds data element to the stack location, where top is pointing.
 Step 5 − Returns success.

If the linked list is used to implement the stack, then in step 3, allocate space dynamically.

You might also like