0% found this document useful (0 votes)
9 views

Data Structure Stack

Uploaded by

Anjneya Vasu X B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Data Structure Stack

Uploaded by

Anjneya Vasu X B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Data Structures

A data structure is a particular way of organizing data in a computer so that it


can be used effectively.
For example, we can store a list of items having the same data-type using
the array data structure.
Types of Data Structures
There are two types of data structures:
 Primitive data structure
 Non-primitive data structure
Primitive Data structure
The int, char, float, double, and pointer are the primitive data
structures that can hold a single value.
Non-Primitive Data structure
The non-primitive data structure is divided into two types:
Linear data structure
Non-linear data structure
Linear Data Structure
The arrangement of data in a sequential manner is known as a
linear data structure. In this data structure each and every
element is attached to its previous and next adjacent element.
The data structures used for this purpose are Arrays, Linked list,
Stacks, and Queues.
Non Linear Data Structure
Data structure where data elements are not arranged
sequentially or linearly are called non linear data structure. In
this data structure single level is not involved. Therefore, we
can’t traverse all the elements in single run only. Example Trees
and graphs.
Major Operations

The major or the common operations that can be performed on the data
structures are:
Searching: We can search for any element in a data structure.
Sorting: We can sort the elements of a data structure either in an ascending or
descending order.
Insertion: We can also insert the new element in a data structure.
Updation: We can also update the element, i.e., we can replace the element
with another element.
Deletion: We can also perform the delete operation to remove the element
from the data
Stack

1. Stack is an ordered list in which, insertion and


deletion can be performed only at one end that is
called top.
2. Stack is a recursive data structure having pointer to
its top element.
3. Stacks are sometimes called as Last-In-First-Out
(LIFO) lists i.e. the element which is inserted first in
the stack, will be deleted last from the stack.
Operations on Stack

There are various operations which can be performed on stack.


1. Push : Adding an element onto the stack
2. Pop : Removing an element from the stack
3. Peek : Look all the elements of stack without removing them
How the stack grows?

Scenario 1 : Stack is empty


The stack is called empty if it doesn't contain any
element inside it. At this stage, the value of variable
top is -1.
Scenario 2 : Stack is not empty

Value of top will get increased by 1 every time when we add any
element to the stack. In the following stack, After adding first
element, top = 2.
Scenario 3 : Deletion of an element

Scenario 3 : Deletion of an element


Value of top will get decreased by 1 whenever an element is
deleted from the stack.
In the following stack, after deleting 10 from the stack, top = 1.
Top and its value

Top position Status of stack


-1 Empty
0 Only one element in the
stack
N-1 Stack is full
N Overflow

You might also like