0% found this document useful (0 votes)
87 views3 pages

What Is Stack Data Structure?

Stack is a linear data structure that follows LIFO (Last In First Out) principle. Elements can only be added to or removed from one end, called the top of the stack. Common operations are push to add an element and pop to remove the top element. A pointer called top always points to the top of the stack. When implementing a stack using a linked list, memory is dynamically allocated in push operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views3 pages

What Is Stack Data Structure?

Stack is a linear data structure that follows LIFO (Last In First Out) principle. Elements can only be added to or removed from one end, called the top of the stack. Common operations are push to add an element and pop to remove the top element. A pointer called top always points to the top of the stack. When implementing a stack using a linked list, memory is dynamically allocated in push operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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