SlideShare a Scribd company logo
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

Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
bca2010
 
Stack project
Stack projectStack project
Stack project
Amr Aboelgood
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
Apurbo Datta
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
Nguync91368
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
kulachihansraj
 
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
Rai University
 
Rana Junaid Rasheed
Rana Junaid RasheedRana Junaid Rasheed
Rana Junaid Rasheed
Rana junaid Rasheed
 
Stacks & Queues
Stacks & QueuesStacks & Queues
Stacks & Queuestech4us
 
02 Stack
02 Stack02 Stack
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
Kuber Chandra
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
Nguync91368
 
data structure, stack, stack data structure
data structure, stack, stack data structuredata structure, stack, stack data structure
data structure, stack, stack data structurepcnmtutorials
 
Queue
QueueQueue
Data Structures
Data StructuresData Structures
Data Structures
Dr.Umadevi V
 
Stack & queue
Stack & queueStack & queue
Stack & queue
Siddique Ibrahim
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
Senthil Kumar
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar 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

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
Balwant Gorad
 
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
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
Rajkiran Nadar
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx01-Introduction of DSA-1.pptx
01-Introduction of DSA-1.pptx
DwijBaxi
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Anil Kumar Prajapati
 
stack_operationss_documentation_file.ppt
stack_operationss_documentation_file.pptstack_operationss_documentation_file.ppt
stack_operationss_documentation_file.ppt
l228296
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
Data structures
Data structuresData structures
Data structures
naveeth babu
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
TobyWtf
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Poulami Das Akuli
 
Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
V.V.Vanniaperumal College for Women
 
Data structure week y 5
Data structure week y 5Data structure week y 5
Data structure week y 5
karmuhtam
 
Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Stacks queues-1220971554378778-9
Stacks queues-1220971554378778-9Getachew Ganfur
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
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
 
QUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptxQUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptx
TajBir4
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
V.V.Vanniaperumal College for Women
 

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
 
stack_operationss_documentation_file.ppt
stack_operationss_documentation_file.pptstack_operationss_documentation_file.ppt
stack_operationss_documentation_file.ppt
 
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
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 

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.