المحاضرة الثامنة: تراكيب البيانات الطابور
TRANSCRIPT
using Java
2015
Data Structure Prepared by: Mahmoud Rafeek Al-farra
in Java
8. Queue
mfarra.cst.ps www.fb.com/MahmoudRFarra
Contents
Implementation of Queue
Queue and priority queue Interface
Introduction
Implementation of priority Queue
Introductionmfarra.cst.ps www.fb.com/MahmoudRFarra
A queue is a first-in, first-out data structure.
Elements are appended to the end of the queue
and are removed from the beginning of the
queue.
In a priority queue, elements are assigned
priorities.
When accessing elements, the element with the
highest priority is removed first.
Introductionmfarra.cst.ps www.fb.com/MahmoudRFarra
Queues are used to prioritize operating system processes and to simulate events in the real world, such as teller lines at banks and the operation of elevators in buildings.
For an interactive demo on how queue work, go to www.cs.armstrong.edu/liang/animation/web/Queue.html
Mohamed
GhadeerAliAhmedHussa
m
Rear Front
Introductionmfarra.cst.ps www.fb.com/MahmoudRFarra
Queue Interfacemfarra.cst.ps www.fb.com/MahmoudRFarra
Priority Queue Interfacemfarra.cst.ps www.fb.com/MahmoudRFarra
Implementation of Queue mfarra.cst.ps www.fb.com/MahmoudRFarra
Exactly as linked list and stack …
Application: Queue of Customersmfarra.cst.ps www.fb.com/MahmoudRFarra
CustomerClass
CusQueueClass
CusSystemClass
In this class we will create an object of CusQueue class, and then manipulates the list using all operations.
The class of linked list members and operation, this class simulate the list of any thing, the object of this class will be created and used in the class of CusSystem.
A self referential class called Employee, contains the attributes and behavior of any Customer.
1
2
3
EnQueue Operationmfarra.cst.ps www.fb.com/MahmoudRFarra
Mohamed
GhadeerAli
Rear Front
AhmedNew item
1
2 X
EnQueue Operationmfarra.cst.ps www.fb.com/MahmoudRFarra
1. public void InQueue(Customer addCus)2. {3. Customer newc = addCus;4. if (Front == null)5. {6. Front = newc;7. Rear = newc;8. newc.next = null;9. }10. else11. {12. newc.next = Rear;13. Rear = newc;14. }15. length++; }
DeQueue Operationmfarra.cst.ps www.fb.com/MahmoudRFarra
Mohamed
GhadeerAli
Rear Front
Ahmad
current
Delete a node from stackmfarra.cst.ps www.fb.com/MahmoudRFarra
1. public void DeQueue() {2. if (Front == null)3. Console.WriteLine("The Queue is Empty!!");4. else5. {6. Customer current;7. Customer pre_current = Rear;8. for (current = Rear; current.next != null; current = current.next)9. pre_current = current;10. Front = pre_current;11. length--;} }
Queue variations mfarra.cst.ps www.fb.com/MahmoudRFarra
Linear queue
Circular queue
Double ended queue
Self Study: Write a report about Circular queue or double ended queue. [GW, N.W]
using Java
2015
FB: M a h m o u d R F a r r aYouTube: M a h m o u d R F a r SlidesShare: mralfarra
Thank you