SlideShare a Scribd company logo
1 of 18
Data Structures: Stack & Queue
01
Mrs. Nimrita Koul
School of Computing & IT
REVA University
Bangalore, India
Contents
1. Data & Data Type
2. Data Structures
3. Stack
1. Structure
2. Operations
3. Applications
4. Queue
1. Structure
2. Operations
3. Applications
4. Variants
2
3
DATA  facts and statistics
Characters:
Grades, Labels
etc.
Text: Names,
Address,
Designations
Numbers : Age,
Distance , Height
etc.
Images, Videos
and Songs
4
Data Types
Primitive Types
Derived Types:
Aggregation of Primitive Types
5
DATA
STRUCTURE-
An organization
of data to suit a
specific
Purpose
STACK
TREE
QUEUE
LIST
HEAP
HASH TABLE
It has data and the operations that
can be done on stored data
6
STACK
A LAST IN-FIRST OUT ARRANGEMENT OF DATA ITEMS
7
Stack Features
Homogeneous Data
Members
Variable Length
LAST IN – FIRST OUT
TOP-An access pointer for
insertions and deletions
Stack Operations
PUSH- Insert Element at
Top, (overflow if full)
POP- Delete Element at
Top, (Underflow if empty)
PEEK- Read the Element at
Top
isEmpty- Check if the Stack
is empty
isFull- Check if the Stack is
Full
push(), pop(), isEmpty(), isFull() and peek() all take O(1) time. There is no loop in
any of these operations.
Objectives
• 1. To develop an algorithm for feature selection
from gene expression data
• 2. To develop an algorithm for inference of gene
regulatory networks
• 3. To develop an algorithm for classification of
tumor samples based on results of 1 and 2.
8
Implementation as an Array
9
void push()
{
if(top>=size-1)
{
printf("ntSTACK FULL");
}
else
{
printf(" Enter a value to
be pushed:");
scanf("%d",&x);
top++;
stack[top]=x;
}
}
void pop()
{
if(top<=-1)
{
printf("nt Stack
EMPTY");
}
else
{
printf("nt The popped
elements is %d",
stack[top]);
top--;
}
}
int size=5;
int stack[size];
int top;
Implementation as a Linked List
10
void push(int value)
{
node *tmp;
tmp =
malloc(sizeof(node));
tmp -> data = value;
tmp -> next = top;
top = tmp;
}
int pop()
{
node *tmp;
int n;
tmp = top;
n = tmp->data;
top = top->next;
free(tmp);
return n;
}
struct node
{
int data;
struct node
*next;
};
node *top;
top = NULL;
Applications of Stack
11
Expression Evaluation
Expression
Conversion
Syntax Parsing
Backtracking
Parenthesis
Check
String
Reversal
Function Call-
Recursion
Parameter Space & Local
Variables Processing
12
QUEUE
A FIRST IN-FIRST OUT ARRANGEMENT OF DATA ITEMS
13
Queue Features
Homogeneous Data
Members
Variable Length
FIRST IN – FIRST OUT
Front is An access pointer
for deletions
Rear is an access pointer
for insertions
Queue Operations
Enqueue()- Insert Element
at rear
Dequeue()- Delete Element
at front
Peek()- get the element at
front without removing it
isEmpty()- Check if the
queue is empty
isFull()- Check if the queue
is Full
14
Operations
Implementation as an Array
15
int enqueue(int data)
{
if(isfull())
return 0;
rear = rear + 1;
queue[rear] = data;
return 1;
}
bool isfull() {
if(rear == size - 1)
return true;
else
return false;
}
int dequeue() {
if(isempty())
return 0;
int data =
queue[front];
front = front + 1;
return data;
}
bool isempty() {
if(front < 0 || front >
rear)
return true;
else
return false;
}
int size=5;
int queue[size];
int front=0;
Int rear=-1;
Implementation as a Linked List
16
void enqueue(queue *q, int
value)
{
node *tmp;
tmp = malloc(sizeof(node));
tmp->data = value;
tmp->next = NULL;
if(!isempty(q))
{
q->rear->next = tmp;
q->rear = tmp;
}
else
{
q->front = q->rear = tmp;
}
q->count++;
}
int dequeue(queue *q)
{
node *tmp;
int n = q->front->data;
tmp = q->front;
q->front = q->front-
>next;
q->count--;
free(tmp);
return(n);
}
struct node
{
int data;
struct node *next; };
struct queue
{
int count;
node *front;
node *rear; };
Void Initialize (queue *q)
{
q->count = 0;
q->front= NULL;
q->rear = NULL; }
Applications of Queue
17
•Serving requests on a single shared resource, like a
printer, CPU task scheduling etc.
•In real life scenario, Call Center phone systems uses
Queues to hold people calling them in an order, until a
service representative is free.
•Handling of interrupts in real-time systems. The
interrupts are handled in the same order as they arrive
i.e First come first served.
Stacks and queues 20 nov 2018

More Related Content

What's hot

Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
tech4us
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structure
pcnmtutorials
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
Navtar Sidhu Brar
 

What's hot (20)

Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Stack project
Stack projectStack project
Stack project
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
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
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queues
 
Data structure
Data structureData structure
Data structure
 
02 Stack
02 Stack02 Stack
02 Stack
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structure
 
Queue
QueueQueue
Queue
 
Data Structures
Data StructuresData Structures
Data Structures
 
Data structures
Data structuresData structures
Data structures
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 

Similar to Stacks and queues 20 nov 2018

Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
Getachew Ganfur
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
tameemyousaf
 
Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...
abhaysingh19149
 

Similar to Stacks and queues 20 nov 2018 (20)

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
 
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
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
Data structures
Data structuresData structures
Data structures
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...Stack and queue power point presentation data structure and algorithms Stack-...
Stack and queue power point presentation data structure and algorithms Stack-...
 
QUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptxQUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptx
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 

Recently uploaded (20)

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 

Stacks and queues 20 nov 2018

  • 1. Data Structures: Stack & Queue 01 Mrs. Nimrita Koul School of Computing & IT REVA University Bangalore, India
  • 2. Contents 1. Data & Data Type 2. Data Structures 3. Stack 1. Structure 2. Operations 3. Applications 4. Queue 1. Structure 2. Operations 3. Applications 4. Variants 2
  • 3. 3 DATA  facts and statistics Characters: Grades, Labels etc. Text: Names, Address, Designations Numbers : Age, Distance , Height etc. Images, Videos and Songs
  • 4. 4 Data Types Primitive Types Derived Types: Aggregation of Primitive Types
  • 5. 5 DATA STRUCTURE- An organization of data to suit a specific Purpose STACK TREE QUEUE LIST HEAP HASH TABLE It has data and the operations that can be done on stored data
  • 6. 6 STACK A LAST IN-FIRST OUT ARRANGEMENT OF DATA ITEMS
  • 7. 7 Stack Features Homogeneous Data Members Variable Length LAST IN – FIRST OUT TOP-An access pointer for insertions and deletions Stack Operations PUSH- Insert Element at Top, (overflow if full) POP- Delete Element at Top, (Underflow if empty) PEEK- Read the Element at Top isEmpty- Check if the Stack is empty isFull- Check if the Stack is Full push(), pop(), isEmpty(), isFull() and peek() all take O(1) time. There is no loop in any of these operations.
  • 8. Objectives • 1. To develop an algorithm for feature selection from gene expression data • 2. To develop an algorithm for inference of gene regulatory networks • 3. To develop an algorithm for classification of tumor samples based on results of 1 and 2. 8
  • 9. Implementation as an Array 9 void push() { if(top>=size-1) { printf("ntSTACK FULL"); } else { printf(" Enter a value to be pushed:"); scanf("%d",&x); top++; stack[top]=x; } } void pop() { if(top<=-1) { printf("nt Stack EMPTY"); } else { printf("nt The popped elements is %d", stack[top]); top--; } } int size=5; int stack[size]; int top;
  • 10. Implementation as a Linked List 10 void push(int value) { node *tmp; tmp = malloc(sizeof(node)); tmp -> data = value; tmp -> next = top; top = tmp; } int pop() { node *tmp; int n; tmp = top; n = tmp->data; top = top->next; free(tmp); return n; } struct node { int data; struct node *next; }; node *top; top = NULL;
  • 11. Applications of Stack 11 Expression Evaluation Expression Conversion Syntax Parsing Backtracking Parenthesis Check String Reversal Function Call- Recursion Parameter Space & Local Variables Processing
  • 12. 12 QUEUE A FIRST IN-FIRST OUT ARRANGEMENT OF DATA ITEMS
  • 13. 13 Queue Features Homogeneous Data Members Variable Length FIRST IN – FIRST OUT Front is An access pointer for deletions Rear is an access pointer for insertions Queue Operations Enqueue()- Insert Element at rear Dequeue()- Delete Element at front Peek()- get the element at front without removing it isEmpty()- Check if the queue is empty isFull()- Check if the queue is Full
  • 15. Implementation as an Array 15 int enqueue(int data) { if(isfull()) return 0; rear = rear + 1; queue[rear] = data; return 1; } bool isfull() { if(rear == size - 1) return true; else return false; } int dequeue() { if(isempty()) return 0; int data = queue[front]; front = front + 1; return data; } bool isempty() { if(front < 0 || front > rear) return true; else return false; } int size=5; int queue[size]; int front=0; Int rear=-1;
  • 16. Implementation as a Linked List 16 void enqueue(queue *q, int value) { node *tmp; tmp = malloc(sizeof(node)); tmp->data = value; tmp->next = NULL; if(!isempty(q)) { q->rear->next = tmp; q->rear = tmp; } else { q->front = q->rear = tmp; } q->count++; } int dequeue(queue *q) { node *tmp; int n = q->front->data; tmp = q->front; q->front = q->front- >next; q->count--; free(tmp); return(n); } struct node { int data; struct node *next; }; struct queue { int count; node *front; node *rear; }; Void Initialize (queue *q) { q->count = 0; q->front= NULL; q->rear = NULL; }
  • 17. Applications of Queue 17 •Serving requests on a single shared resource, like a printer, CPU task scheduling etc. •In real life scenario, Call Center phone systems uses Queues to hold people calling them in an order, until a service representative is free. •Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive i.e First come first served.