data structure (queue)
TRANSCRIPT
![Page 1: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/1.jpg)
Queue
Adam M.B.
![Page 2: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/2.jpg)
DEFINITION
![Page 3: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/3.jpg)
Queue
• queue is data structure whose its
elemen can be added in the last
element and taken only from the
first element.
• Known as FIFO (First In First Out).
![Page 4: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/4.jpg)
Components of Queue• Front is a variable which refers to first
position in queue.
• Rear is a variable which refers to last position in queue.
• Element is component which has data.
• MaxQueue is variable that describes maximum number of elements in a queue.
![Page 5: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/5.jpg)
DECLARATION
![Page 6: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/6.jpg)
Declaration as ArrayKamus:
Const
MaxQueue = value {value is integer number}
Type
NamaQueue = array [1..MaxQueue] of tipedata
Queue : NamaQueue
Front, Rear : integer {pointer of Queue}
![Page 7: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/7.jpg)
Declaration as ArrayKamus:
Const
MaxQueue = 4
Type
ArrayQueue = array [1..MaxQueue] of integer
Queue : ArrayQueue
Front, Rear : integer {pointer of Queue}
![Page 8: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/8.jpg)
Declaration as ListKamus:
Type
NamaPointer = ↑Queue Queue = Record
< MedanData : TipeData,
MedanSambungan : NamaPointer >
EndRecord
Front, Rear : NamaPointer {pointer of queue}
![Page 9: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/9.jpg)
Declaration as ListKamus:
Type
Point = ↑Queue Queue = Record
< Angka : integer,
Next : Point >
EndRecord
Front, Rear : Point {pointer of queue}
![Page 10: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/10.jpg)
OPERATION
![Page 11: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/11.jpg)
Operation• Initialization
• Empty Operation
• Full Operation (array)/One Node
Operation (Linked List)
• Enqueue
• Dequeue
![Page 12: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/12.jpg)
Main Operation
Enqueue
Queue
Take data from element
in queue.
DequeueAdd data to
element in queue.
![Page 13: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/13.jpg)
Kinds of Operation
•Queue Operation in linear array form
•Queue Operation in Linked list form
•Queue Operation in circular array
form
![Page 14: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/14.jpg)
QUEUE OPERATION IN ARRAY FORM
![Page 15: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/15.jpg)
Operation that give a initial value for front and rear pointer in queue with the following rules:• Give 0 if the first element starts
from 1• Give -1 if the first element starts
from 0
Initialization
![Page 16: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/16.jpg)
Operation that returns true if the rear pointer have 0 or -1 as its value (depend on initialization) or returns
false to the contrary.
Empty Operation
![Page 17: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/17.jpg)
Operation that returns true if rear has reached maximum array or maximum array -1 (depend on
initialization) or returns false if top is not equal to maximum array.
Full Operation
![Page 18: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/18.jpg)
Steps in enqueue operation:• Queue can be added when it’s not full• If queue is empty then front and rear is
added by 1. For the contrary, rear is added by 1.
• Queue element, which was refered by rear pointer, is filled with new data.
Enqueue
![Page 19: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/19.jpg)
Enqueue
Enqueue(Front,Rear,Queue,8)
Enqueue(Front,Rear,Queue,3)Enqueue(Front,Rear,Queue,5)
Enqueue(Front,Rear,Queue,7)“Queue is full”
Queue1 2 3 40
front rear
3 5 8 7
Enqueue(Front,Rear,Queue,2)
![Page 20: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/20.jpg)
Steps in dequeue operation:• Queue can be dequeue when its
elements is not empty.• After first element is taken out from
queue then second element in queue will be shifted into first element and so on.
• Substract the rear pointer with 1.
Dequeue
![Page 21: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/21.jpg)
Dequeue
Queue1 2 3 40
front rear
3 5 8 7
Dequeue(Front,Rear,Queue,Item)
“Queue is Empty”
Dequeue(Front,Rear,Queue,Item)Dequeue(Front,Rear,Queue,Item)Dequeue(Front,Rear,Queue,Item)Dequeue(Front,Rear,Queue,Item)
Item35 8 58 7 877 7
![Page 22: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/22.jpg)
QUEUE OPERATION IN LINKED LIST
FORM
![Page 23: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/23.jpg)
Prepare queue by giving null value to the front and rear pointer in queue.
Initialization
![Page 24: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/24.jpg)
Operation that returns true if the
rear pointer is null or returns false to the contrary.
Empty Operation
![Page 25: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/25.jpg)
Operation that returns true if rear and front refer to same node (queue
only has one node) or returns false to the contrary.
One Node Operation
![Page 26: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/26.jpg)
Steps of enqueue operation in linked
list form is similar with back insertion.
Enqueue
![Page 27: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/27.jpg)
Enqueue
Enqueue(Front,Rear,8)
baru 8
Front
Queue is empty
Rear
![Page 28: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/28.jpg)
Enqueue
Enqueue(Front,Rear,3)
baru 3
8
Front
Queue isn’t empty
Rear
![Page 29: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/29.jpg)
Enqueue
Enqueue(Front,Rear,5)
baru 5
8
Front
Queue isn’t emptyRear
3
![Page 30: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/30.jpg)
Steps of dequeue operation in linked
list form is similar with front deletion.
Dequeue
![Page 31: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/31.jpg)
Dequeue Dequeue(Front,Rear,Item)
58
Front Rear
3
{Queue > One node}
Item
Phapus
![Page 32: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/32.jpg)
Dequeue Dequeue(Front,Rear,Item)
5
Front
3
{Queue > one node}
Item
Phapus Rear
![Page 33: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/33.jpg)
Dequeue Dequeue(Front,Rear,Item)
5
Front
{Queue = one node}
Item
Phapus
Rear Front Rear
![Page 34: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/34.jpg)
QUEUE OPERATION IN CIRCULAR ARRAY FORM
![Page 35: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/35.jpg)
Steps in enqueue operation:• Queue can be added when it’s not full• If queue is empty then front and rear is
added by 1. If it isn’t empty then rear is added by 1 but if rear is at maximum queue then rear = 1.
• Queue element, which was refered by rear pointer, is filled with new data.
Enqueue
![Page 36: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/36.jpg)
Steps in dequeue operation:• Queue can be dequeue when its
elements is not empty.• If it isn’t empty then front is added by
1.• If front is at maximum queue then front
= 1.
Dequeue
![Page 37: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/37.jpg)
Enqueue and Dequeue
Enqueue(Front,Rear,Queue,8)Enqueue(Front,Rear,Queue,3)Enqueue(Front,Rear,Queue,5)Dequeue(Front,Rear,Queue,item)Enqueue(Front,Rear,Queue,7)
“Queue is full”
Queue1 2 3 40
front rear
8 3 5 7
Enqueue(Front,Rear,Queue,2)Enqueue(Front,Rear,Queue,9)
2
Dequeue(Front,Rear,Queue,item)8Enqueue(Front,Rear,Queue,12)
Item3
9
![Page 38: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/38.jpg)
Do the task 6.46 and 6.48 in page 212 at Data Structures book, seymour.
Exercise
![Page 39: Data Structure (Queue)](https://reader037.vdocuments.net/reader037/viewer/2022110109/587831221a28abef5d8b6a19/html5/thumbnails/39.jpg)
Contact Person:Adam Mukharil Bachtiar
Informatics Engineering UNIKOMJalan Dipati Ukur Nomor. 112-114 Bandung 40132
Email: [email protected]: http://adfbipotter.wordpress.com
Copyright © Adam Mukharil Bachtiar 2012
GRACIASTHANK YOU