SlideShare a Scribd company logo
1 of 18
Data Structure
(KCS-301)
Arvind Kumar
Assistant Professor
CSE/IT Dept.
Data Structure
(KCS-301)
Unit-2
Stack
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, the only element that can be removed is the element that was
at the top of the stack.
Stack
Basic features of Stack
Stack is an ordered list of similar data type.
Stack is a LIFO structure. (Last in First out).
push() function is used to insert new elements into the Stack and pop()
is used to delete an element from the stack. Both insertion and deletion
are allowed at only one end of Stack called Top.
Stack is said to be in Overflow state when it is completely full and is
said to be in Underflow state if it is completely empty.
Applications of Stack
The simplest application of a stack is to reverse a word. You push a
given word to stack - letter by letter - and then pop letters from the
stack.
There are other uses also like : Parsing, Expression Conversion(Infix
to Postfix, Postfix to Prefix etc) and many more.
Stack Operation
Algorithm for Stacks:
Push operation.
If(TOS= Maxsize-1)
Then print Insertion is not possible
Else
Set TOS=TOS+1
Set S[Tos]=data
Exit
Pop Operation.
If (TOS==-1)
Then print deletion is not possible
Else
Data=S[TOS]
Set TOS=TOS-1
Exit
Linked List Representation of Stack:
#include<stdio.h>
#include<conio.h>
struct stu *new(int)
void addnode( );
void traverse( );
void delfirst();
struct stu
{
Int info;
Struct stu * next;
}
*head=NULL, *temp,*p;
Void main( )
{
int a, ch=1,choice, data;
while( ch)
{
Printf(“Enter the choice”);
Scanf(“%d”,&choice);
Switch(choice)
{
Case:1
Printf(“enter the data to be inserted”);
Scanf(“%d”,&a);
P=new(a);
addnode(p);
traverse();
break;
case 2:
delfirst( );
traverse();
break;
case 3:
exit( );
}
}
}
Struct stu *new ( int a)
{
p=((struct stu *) malloc (sizeof(struct
stu)));
p – info=a;
p – next=NULL;
return p;
}
Void addnode( )
{
Temp=head;
If (head==NULL)
{
Head=p;
}
Else
{
P –> next=temp;
Head=p;
}
Void traverse
{
Temp=head;
While(temp!=NULL)
{
Printf(“%d”, temp- info);
Temp=temp – next;
}
}
Void delfirst( )
{
Temp=head;
If(head==NULL)
{
Printf(“ Stack is empty”);
}
Else
{
Head=temp->next;
Free(temp);
}
}
Infix, Postfix and Prefix
Infix, Postfix and Prefix notations are three different but equivalent ways
of writing expressions. It is easiest to demonstrate the differences by
looking at examples of operators that take two operands.
Infix notation: X + Y
Postfix notation (also known as "Reverse Polish notation"): X Y +
Prefix notation (also known as "Polish notation"): + X Y
Converting between these notations
The most straightforward method is to start by inserting all the implicit
brackets that show the order of evaluation e.g.:
Infix Postfix Prefix
( (A * B) + (C / D) ) ( (A B *) (C D /) +) (+ (* A B) (/ C D) )
((A * (B + C) ) / D) ( (A (B C +) *) D /) (/ (* A (+ B C) ) D)
Queue Data Structures
Queue is also an abstract data type or a linear data structure, in which the first
element is inserted from one end called REAR(also called tail), and the
deletion of exisiting element takes place from the other end called as
FRONT(also called head). This makes queue as FIFO data structure, which
means that element inserted first will also be removed first.
The process to add an element into queue is called Enqueue and the process of
removal of an element from queue is called Dequeue.
Queue
Basic features of Queue
• Like Stack, Queue is also an ordered list of elements of similar
data types.
• Queue is a FIFO( First in First Out ) structure.
• Once a new element is inserted into the Queue, all the
elements inserted before the new element in the queue must be
removed, to remove the new element.
• peek( ) function is oftenly used to return the value of first
element without dequeuing it.
Implementation of queue
Initially the head(FRONT) and the tail(REAR) of the queue points at the first
index of the array (starting the index of array from 0). As we add elements to
the queue, the tail keeps on moving ahead, always pointing to the position
where the next element will be inserted, while the head remains at the first
index.
Queue
Queue is a linear data structure in which insertion and deletion is performed at two ends:
Rear end: Insertion takes place
Front end: Deletion takes place
Algorithms for Queue:
Insertion:
If ( front=0 && rear=size-1)
Then print insertion not possible
Elseif ( rear=-1 && front=-1)
Then set rear=0 and front=0
Else
Set rear=rear+1
Set Q[rear]=data
Exit
Deletion:
If(front=-1 or front>rear)
Then print deletion not possible
Set data=Q[font];
Front=front+1
Exit
Linked List Representation of Queue:
#include<stdio.h>
#include<conio.h>
struct stu *new(int)
void addnode( );
void traverse( );
void delfirst();
struct stu
{
Int info;
Struct stu * next;
}
*head=NULL, *temp,*p;
Void main( )
{
int a, ch=1,choice, data;
while( ch)
{
Printf(“Enter the choice”);
Scanf(“%d”,&choice);
Switch(choice)
{
Case:1
Printf(“enter the data to be inserted”);
Scanf(“%d”,&a);
P=new(a);
addnode(p);
traverse();
break;
case 2:
delfirst( );
traverse();
break;
case 3:
exit( );
}
}
}
Struct stu *new ( int a)
{
p=((struct stu *) malloc (sizeof(struct stu)));
p – info=a;
p – next=NULL;
return p;
}
Void addnode( )
{
Temp=head;
If (head==NULL)
{
Head=p;
}
Else
{
While(temp->next!=NULL)
{
Temp=temp->next;
}
Temp->next=p;
}
}
Void traverse
{
Temp=head;
While(temp!=NULL)
{
Printf(“%d”, temp- info);
Temp=temp – next;
}
}
Void delfirst( )
{
Temp=head;
If(head==NULL)
{
Printf(“ Stack is empty”);
}
Else
{
Head=temp->next;
Free(temp);
}
}
Circular Queue
when the queue becomes full or rear=maxsize-1, then no more data can be inserted.But, if there is space at the
front end after deleting the elements, then the space can be utilized using circular queues
In circular queue, the first index comes after the right index
Operations on Queues:
Insertion
If front=0 and rear=maxsize-1
Then print insertion not possible
Else if front=-1 and rear=-1
Then set front=0 and rear=0
Else if front!=0 and rear=maxsize-1
Then set rear=0
Else set rear=rear+1
Set Q[rear]=data
Exit
Deletion
If front=-1
Then print deletion not possible
Set data=Q[front];
If front=rear
Then set front =front+1
Else if front=maxsize-1
Then set front=0
Else set front=front+1
Exit
Program on Array Representation of Circular Queue
#include<stdio.h>
#include<conio.h>
int S[10];
int rear=-1,front=-1,size=10;
void insert();
int delete();
void traverse();
void main()
{
int ch=1,choice,data;
while(ch)
{
printf("Enter the choice");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the value to be inserted");
scanf("%d",&data);
insert(data);
traverse();
break;
case 2:
data=delete();
printf("The element deleted is %d",data);
traverse();
break;
case 0:
exit();
}
}
}
void insert(int data)
{
if((front==0) && (rear==size-1))
{
printf("Insertion not possible");
}
else if((front==-1)&&(rear==-1))
{
rear=front=0;
}
else if((front!=0) && (rear==size-1))
{
rear=0;
}
else
{
rear=rear+1;
}
S[rear]=data;
}
int delete()
{
int data;
if(front==-1)
{
printf("deletion not possible");
}
data=S[front];
if(front==rear)
{
front=front+1;
}
else if(front==size-1)
{
front=0;
}
else
{
front=front+1;
}
return data;
}
void traverse()
{
int i;
for(i=front;i<=rear;i++)
{
printf("The list is %d",S[i]);
}
}
Dequeue
Dequeue
It is called Circular Double Ended Queue
Operations of insertion and deletion can be performed at both the ends
These are of two types:
Input Restricted Queue: Insertion is performed at one end while
deletion is performed at both ends
Output restricted Queue: Deletion is performed at single end while
insertion is performed at both ends
Algorithm for Deques:
Insert-Right
If front=0 and rear=masize-1 or front=rear+1
Then print insertion not possible
Else if front=-1
Then set front=0 and rear=0
Else if rear=maxsize-1
Then set rear=0
Else
Set rear=rear+1
Q[rear]=data
Exit
Insert-Left
If front =0 and rear=maxsize-1 or left=right+1
Then print insertion not possible
Else If front=-1
Then set front=0 and rear=0
Else if front=0 and rear!=maxsize-1
Then set front=maxsize-1
Else set front=front-1
Set data=Q[front]
Exit
Delete-Right
If right=-1
Then print deletion not possible
Data=Q[front]
If front=rear
Then set front=0 and rear=0
Else set rear=rear-1
Exit
Delete-left
If front= -1
Then print deletion not possible
Data=Q[front]
If front =rear=0
Then set front=-1 and rear=-1
Else
Set front=front +1
Exit
Priority Queue
Priority Queue
A priority queue is a queue in which each element is assigned a priority.
The priority of each element determines the order in which each
elements will be processed.
Rules for creating priority queue:
An element with higher priority is processed before an element with
lower priority
Two elements with the same priority are processed on First come- First
serve basis (FCFS)
Tower of Hanoi
It is one of the main applications of recursion
The problem is stated as:
• There are 3 disks mounted on a pole A. the problem is to move all
these rings from pole A to pole C using the intermediary pole B.
The rules which govern the problem are:
• Only one disk can be moved at one time
• The smaller disk must always come above the larger disk
Algorithm:
If n=1, move the ring directly from A to C
Else move n-1 rings from A to B
Move nth ring from A to C
Move n-1 rings from B to C

More Related Content

What's hot

Data Structures In Scala
Data Structures In ScalaData Structures In Scala
Data Structures In ScalaKnoldus Inc.
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueRai University
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data StructureSriram Raj
 
Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaVladimir Kostyukov
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queueTareq Hasan
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Meghaj Mallick
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structureeShikshak
 
Queue data structure
Queue data structureQueue data structure
Queue data structureanooppjoseph
 

What's hot (20)

Data Structures In Scala
Data Structures In ScalaData Structures In Scala
Data Structures In Scala
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Stacks queues
Stacks queuesStacks queues
Stacks queues
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in Scala
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
Queue
QueueQueue
Queue
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Stack data structure in Data Structure using C
Stack data structure in Data Structure using C Stack data structure in Data Structure using C
Stack data structure in Data Structure using C
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 

Similar to data structure

03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptxsinghprpg
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queuessuser7319f8
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-listpinakspatel
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptxSajalFayyaz
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptxSonaPathak4
 
Queues presentation
Queues presentationQueues presentation
Queues presentationToseef Hasan
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdfpasqualealvarez467
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
 
Data Structures and Files
Data Structures and FilesData Structures and Files
Data Structures and FilesKanchanPatil34
 
Ch03_stacks_and_queues.ppt
Ch03_stacks_and_queues.pptCh03_stacks_and_queues.ppt
Ch03_stacks_and_queues.pptOliverKane3
 

Similar to data structure (20)

Data structure
Data  structureData  structure
Data structure
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Stacks,queues,linked-list
Stacks,queues,linked-listStacks,queues,linked-list
Stacks,queues,linked-list
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
05 queues
05 queues05 queues
05 queues
 
Stacks
StacksStacks
Stacks
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
 
Unit6 C
Unit6 C Unit6 C
Unit6 C
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Data Structures and Files
Data Structures and FilesData Structures and Files
Data Structures and Files
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
04 stacks
04 stacks04 stacks
04 stacks
 
Ch03_stacks_and_queues.ppt
Ch03_stacks_and_queues.pptCh03_stacks_and_queues.ppt
Ch03_stacks_and_queues.ppt
 
Queue
QueueQueue
Queue
 

More from Arvind Kumar

3 d transformation reflection
3 d transformation   reflection3 d transformation   reflection
3 d transformation reflectionArvind Kumar
 
3 d transformation Rotation
3 d transformation   Rotation3 d transformation   Rotation
3 d transformation RotationArvind Kumar
 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curveArvind Kumar
 
3 D transformation translation, scaling
3 D transformation   translation, scaling3 D transformation   translation, scaling
3 D transformation translation, scalingArvind Kumar
 
Curve and text clipping
Curve and text clippingCurve and text clipping
Curve and text clippingArvind Kumar
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmArvind Kumar
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingArvind Kumar
 

More from Arvind Kumar (9)

3 d transformation reflection
3 d transformation   reflection3 d transformation   reflection
3 d transformation reflection
 
3 d transformation Rotation
3 d transformation   Rotation3 d transformation   Rotation
3 d transformation Rotation
 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curve
 
3d Projection
3d Projection3d Projection
3d Projection
 
3 D transformation translation, scaling
3 D transformation   translation, scaling3 D transformation   translation, scaling
3 D transformation translation, scaling
 
Curve and text clipping
Curve and text clippingCurve and text clipping
Curve and text clipping
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping Algorithm
 
Weiler atherton
Weiler athertonWeiler atherton
Weiler atherton
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 

data structure

  • 3. Stack 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, the only element that can be removed is the element that was at the top of the stack.
  • 4. Stack Basic features of Stack Stack is an ordered list of similar data type. Stack is a LIFO structure. (Last in First out). push() function is used to insert new elements into the Stack and pop() is used to delete an element from the stack. Both insertion and deletion are allowed at only one end of Stack called Top. Stack is said to be in Overflow state when it is completely full and is said to be in Underflow state if it is completely empty. Applications of Stack The simplest application of a stack is to reverse a word. You push a given word to stack - letter by letter - and then pop letters from the stack. There are other uses also like : Parsing, Expression Conversion(Infix to Postfix, Postfix to Prefix etc) and many more.
  • 5. Stack Operation Algorithm for Stacks: Push operation. If(TOS= Maxsize-1) Then print Insertion is not possible Else Set TOS=TOS+1 Set S[Tos]=data Exit Pop Operation. If (TOS==-1) Then print deletion is not possible Else Data=S[TOS] Set TOS=TOS-1 Exit
  • 6. Linked List Representation of Stack: #include<stdio.h> #include<conio.h> struct stu *new(int) void addnode( ); void traverse( ); void delfirst(); struct stu { Int info; Struct stu * next; } *head=NULL, *temp,*p; Void main( ) { int a, ch=1,choice, data; while( ch) { Printf(“Enter the choice”); Scanf(“%d”,&choice); Switch(choice) { Case:1 Printf(“enter the data to be inserted”); Scanf(“%d”,&a); P=new(a); addnode(p); traverse(); break; case 2: delfirst( ); traverse(); break; case 3: exit( ); } } } Struct stu *new ( int a) { p=((struct stu *) malloc (sizeof(struct stu))); p – info=a; p – next=NULL; return p; } Void addnode( ) { Temp=head; If (head==NULL) { Head=p; } Else { P –> next=temp; Head=p; } Void traverse { Temp=head; While(temp!=NULL) { Printf(“%d”, temp- info); Temp=temp – next; } } Void delfirst( ) { Temp=head; If(head==NULL) { Printf(“ Stack is empty”); } Else { Head=temp->next; Free(temp); } }
  • 7. Infix, Postfix and Prefix Infix, Postfix and Prefix notations are three different but equivalent ways of writing expressions. It is easiest to demonstrate the differences by looking at examples of operators that take two operands. Infix notation: X + Y Postfix notation (also known as "Reverse Polish notation"): X Y + Prefix notation (also known as "Polish notation"): + X Y Converting between these notations The most straightforward method is to start by inserting all the implicit brackets that show the order of evaluation e.g.: Infix Postfix Prefix ( (A * B) + (C / D) ) ( (A B *) (C D /) +) (+ (* A B) (/ C D) ) ((A * (B + C) ) / D) ( (A (B C +) *) D /) (/ (* A (+ B C) ) D)
  • 8. Queue Data Structures Queue is also an abstract data type or a linear data structure, in which the first element is inserted from one end called REAR(also called tail), and the deletion of exisiting element takes place from the other end called as FRONT(also called head). This makes queue as FIFO data structure, which means that element inserted first will also be removed first. The process to add an element into queue is called Enqueue and the process of removal of an element from queue is called Dequeue.
  • 9. Queue Basic features of Queue • Like Stack, Queue is also an ordered list of elements of similar data types. • Queue is a FIFO( First in First Out ) structure. • Once a new element is inserted into the Queue, all the elements inserted before the new element in the queue must be removed, to remove the new element. • peek( ) function is oftenly used to return the value of first element without dequeuing it.
  • 10. Implementation of queue Initially the head(FRONT) and the tail(REAR) of the queue points at the first index of the array (starting the index of array from 0). As we add elements to the queue, the tail keeps on moving ahead, always pointing to the position where the next element will be inserted, while the head remains at the first index.
  • 11. Queue Queue is a linear data structure in which insertion and deletion is performed at two ends: Rear end: Insertion takes place Front end: Deletion takes place Algorithms for Queue: Insertion: If ( front=0 && rear=size-1) Then print insertion not possible Elseif ( rear=-1 && front=-1) Then set rear=0 and front=0 Else Set rear=rear+1 Set Q[rear]=data Exit Deletion: If(front=-1 or front>rear) Then print deletion not possible Set data=Q[font]; Front=front+1 Exit
  • 12. Linked List Representation of Queue: #include<stdio.h> #include<conio.h> struct stu *new(int) void addnode( ); void traverse( ); void delfirst(); struct stu { Int info; Struct stu * next; } *head=NULL, *temp,*p; Void main( ) { int a, ch=1,choice, data; while( ch) { Printf(“Enter the choice”); Scanf(“%d”,&choice); Switch(choice) { Case:1 Printf(“enter the data to be inserted”); Scanf(“%d”,&a); P=new(a); addnode(p); traverse(); break; case 2: delfirst( ); traverse(); break; case 3: exit( ); } } } Struct stu *new ( int a) { p=((struct stu *) malloc (sizeof(struct stu))); p – info=a; p – next=NULL; return p; } Void addnode( ) { Temp=head; If (head==NULL) { Head=p; } Else { While(temp->next!=NULL) { Temp=temp->next; } Temp->next=p; } } Void traverse { Temp=head; While(temp!=NULL) { Printf(“%d”, temp- info); Temp=temp – next; } } Void delfirst( ) { Temp=head; If(head==NULL) { Printf(“ Stack is empty”); } Else { Head=temp->next; Free(temp); } }
  • 13. Circular Queue when the queue becomes full or rear=maxsize-1, then no more data can be inserted.But, if there is space at the front end after deleting the elements, then the space can be utilized using circular queues In circular queue, the first index comes after the right index Operations on Queues: Insertion If front=0 and rear=maxsize-1 Then print insertion not possible Else if front=-1 and rear=-1 Then set front=0 and rear=0 Else if front!=0 and rear=maxsize-1 Then set rear=0 Else set rear=rear+1 Set Q[rear]=data Exit Deletion If front=-1 Then print deletion not possible Set data=Q[front]; If front=rear Then set front =front+1 Else if front=maxsize-1 Then set front=0 Else set front=front+1 Exit
  • 14. Program on Array Representation of Circular Queue #include<stdio.h> #include<conio.h> int S[10]; int rear=-1,front=-1,size=10; void insert(); int delete(); void traverse(); void main() { int ch=1,choice,data; while(ch) { printf("Enter the choice"); scanf("%d",&choice); switch(choice) { case 1: printf("Enter the value to be inserted"); scanf("%d",&data); insert(data); traverse(); break; case 2: data=delete(); printf("The element deleted is %d",data); traverse(); break; case 0: exit(); } } } void insert(int data) { if((front==0) && (rear==size-1)) { printf("Insertion not possible"); } else if((front==-1)&&(rear==-1)) { rear=front=0; } else if((front!=0) && (rear==size-1)) { rear=0; } else { rear=rear+1; } S[rear]=data; } int delete() { int data; if(front==-1) { printf("deletion not possible"); } data=S[front]; if(front==rear) { front=front+1; } else if(front==size-1) { front=0; } else { front=front+1; } return data; } void traverse() { int i; for(i=front;i<=rear;i++) { printf("The list is %d",S[i]); } }
  • 15. Dequeue Dequeue It is called Circular Double Ended Queue Operations of insertion and deletion can be performed at both the ends These are of two types: Input Restricted Queue: Insertion is performed at one end while deletion is performed at both ends Output restricted Queue: Deletion is performed at single end while insertion is performed at both ends
  • 16. Algorithm for Deques: Insert-Right If front=0 and rear=masize-1 or front=rear+1 Then print insertion not possible Else if front=-1 Then set front=0 and rear=0 Else if rear=maxsize-1 Then set rear=0 Else Set rear=rear+1 Q[rear]=data Exit Insert-Left If front =0 and rear=maxsize-1 or left=right+1 Then print insertion not possible Else If front=-1 Then set front=0 and rear=0 Else if front=0 and rear!=maxsize-1 Then set front=maxsize-1 Else set front=front-1 Set data=Q[front] Exit Delete-Right If right=-1 Then print deletion not possible Data=Q[front] If front=rear Then set front=0 and rear=0 Else set rear=rear-1 Exit Delete-left If front= -1 Then print deletion not possible Data=Q[front] If front =rear=0 Then set front=-1 and rear=-1 Else Set front=front +1 Exit
  • 17. Priority Queue Priority Queue A priority queue is a queue in which each element is assigned a priority. The priority of each element determines the order in which each elements will be processed. Rules for creating priority queue: An element with higher priority is processed before an element with lower priority Two elements with the same priority are processed on First come- First serve basis (FCFS)
  • 18. Tower of Hanoi It is one of the main applications of recursion The problem is stated as: • There are 3 disks mounted on a pole A. the problem is to move all these rings from pole A to pole C using the intermediary pole B. The rules which govern the problem are: • Only one disk can be moved at one time • The smaller disk must always come above the larger disk Algorithm: If n=1, move the ring directly from A to C Else move n-1 rings from A to B Move nth ring from A to C Move n-1 rings from B to C