SlideShare a Scribd company logo
1 of 7
Queue:
A queue, also called FIFO system, is a linear list in which deletions can
take place only at one end of the list, the Front of the list and
insertion can take place only at the other end Rear.
Implementation of Queue by using array:
front = -1
rear = -1
A
Insert (A)
front = 0
rear = 0
A B
Insert (B)
front = 0
rear = 1
A B C
Insert (C)
front = 0
rear = 2
B C
Delete
front = 1
rear = 2
C
Delete
front = 2
rear = 2
QINSERT(QUEUE, N, FRONT, REAR, ELE)
1. If REAR = N-1 then
Write : OVERFLOW, and Return
2. If FRONT = -1 then
Set FRONT = 0 and REAR = 0
Else
Set REAR = REAR+1
3. Set QUEUE[REAR] = ELE
4. Return
int add(struct queue *q, int ele)
{
if (q->rear == Max-1)
return(0);
if (q->front == -1)
{
q->front = 0;
q->rear = 0;
}
else
q->rear++;
q->item[q->rear]=ele;
return (1);
}
struct queue
{
int item[Max];
int front,rear;
};
QDELETE(QUEUE, N, FRONT, REAR, ELE)
1. If FRONT = -1 or FRONT > REAR and then
Write : UNDERFLOW, and Return
2. Set ELE = QUEUE[FRONT]
3. Set FRONT = FRONT+1
4. Return
int del(struct queue *q, int *ele)
{
if (q->front ==-1 || q->front > q->rear)
return (0);
*ele=q->item[q->front];
q->front++;
return(1);
}
With this implementation there is one drawback. After Max
insertions, the last element will occupy the last position of the array.
This occurs even though the queue itself may not contain any
elements.
Suppose we want to insert an element into a queue when there are
some empty locations at the beginning of the array. One way is to
simply move the entire queue to the beginning of the array. This
procedure may be very expensive.
Another way is by assuming that the array is circular, that is, That
QUEUE[0] comes after QUEUE[Max-1] in the array.
0 1 Max-1
CQINSERT(QUEUE, N, FRONT, REAR, ITEM)
1. If FRONT = 0 and REAR =N-1 or if FRONT=REAR +1 then
Write : OVERFLOW, and Return
2. If FRONT = -1 then
Set FRONT = 0 and REAR = 0
Else if REAR = N-1, then
Set REAR = 0
Else
Set REAR = REAR+1
3. Set QUEUE[REAR] = ITEM
4. Return
CQDELETE(QUEUE, N, FRONT, REAR, ITEM)
1. If FRONT = -1 then
Write : UNDERFLOW, and Return
2. Set ITEM = QUEUE[FRONT]
3. If FRONT = REAR then
Set FRONT = -1 and REAR = -1
Else if FRONT = N-1, then
Set FRONT = 0
Else
Set FRONT = FRONT+1
4. Return

More Related Content

Similar to Computer Engineering Data Structure Queue.pptx

Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
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
 
6 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart36 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart3SSE_AndyLi
 
Queues and Stacks
Queues and StacksQueues and Stacks
Queues and StacksProf Ansari
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queueskalyanineve
 
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
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applicationssomendra kumar
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms QueuesManishPrajapati78
 
A sorted linear array
A sorted linear array A sorted linear array
A sorted linear array Suneel Dogra
 
08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertexSadiaSharmin40
 

Similar to Computer Engineering Data Structure Queue.pptx (20)

Queue
QueueQueue
Queue
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Stack q ll algo
Stack q ll algoStack q ll algo
Stack q ll algo
 
Queue
QueueQueue
Queue
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Unit 7 sorting
Unit 7   sortingUnit 7   sorting
Unit 7 sorting
 
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
 
6 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart36 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart3
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
Queues and Stacks
Queues and StacksQueues and Stacks
Queues and Stacks
 
Stacks queues
Stacks queuesStacks queues
Stacks queues
 
Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
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
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Data Structure and Algorithms Queues
Data Structure and Algorithms QueuesData Structure and Algorithms Queues
Data Structure and Algorithms Queues
 
A sorted linear array
A sorted linear array A sorted linear array
A sorted linear array
 
08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex
 
Queue
QueueQueue
Queue
 

Recently uploaded

(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
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
 
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
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(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
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
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 and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 

Recently uploaded (20)

(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
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 )
 
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
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(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
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
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 and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
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
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 

Computer Engineering Data Structure Queue.pptx

  • 1. Queue: A queue, also called FIFO system, is a linear list in which deletions can take place only at one end of the list, the Front of the list and insertion can take place only at the other end Rear.
  • 2. Implementation of Queue by using array: front = -1 rear = -1 A Insert (A) front = 0 rear = 0 A B Insert (B) front = 0 rear = 1 A B C Insert (C) front = 0 rear = 2 B C Delete front = 1 rear = 2 C Delete front = 2 rear = 2
  • 3. QINSERT(QUEUE, N, FRONT, REAR, ELE) 1. If REAR = N-1 then Write : OVERFLOW, and Return 2. If FRONT = -1 then Set FRONT = 0 and REAR = 0 Else Set REAR = REAR+1 3. Set QUEUE[REAR] = ELE 4. Return int add(struct queue *q, int ele) { if (q->rear == Max-1) return(0); if (q->front == -1) { q->front = 0; q->rear = 0; } else q->rear++; q->item[q->rear]=ele; return (1); } struct queue { int item[Max]; int front,rear; };
  • 4. QDELETE(QUEUE, N, FRONT, REAR, ELE) 1. If FRONT = -1 or FRONT > REAR and then Write : UNDERFLOW, and Return 2. Set ELE = QUEUE[FRONT] 3. Set FRONT = FRONT+1 4. Return int del(struct queue *q, int *ele) { if (q->front ==-1 || q->front > q->rear) return (0); *ele=q->item[q->front]; q->front++; return(1); }
  • 5. With this implementation there is one drawback. After Max insertions, the last element will occupy the last position of the array. This occurs even though the queue itself may not contain any elements. Suppose we want to insert an element into a queue when there are some empty locations at the beginning of the array. One way is to simply move the entire queue to the beginning of the array. This procedure may be very expensive. Another way is by assuming that the array is circular, that is, That QUEUE[0] comes after QUEUE[Max-1] in the array. 0 1 Max-1
  • 6. CQINSERT(QUEUE, N, FRONT, REAR, ITEM) 1. If FRONT = 0 and REAR =N-1 or if FRONT=REAR +1 then Write : OVERFLOW, and Return 2. If FRONT = -1 then Set FRONT = 0 and REAR = 0 Else if REAR = N-1, then Set REAR = 0 Else Set REAR = REAR+1 3. Set QUEUE[REAR] = ITEM 4. Return
  • 7. CQDELETE(QUEUE, N, FRONT, REAR, ITEM) 1. If FRONT = -1 then Write : UNDERFLOW, and Return 2. Set ITEM = QUEUE[FRONT] 3. If FRONT = REAR then Set FRONT = -1 and REAR = -1 Else if FRONT = N-1, then Set FRONT = 0 Else Set FRONT = FRONT+1 4. Return