المحاضرة الثامنة: تراكيب البيانات الطابور

15
using Java 2015 Data Structure Prepared by: Mahmoud Rafeek Al-farra in Java 8. Queue

Upload: mahmoud-alfarra

Post on 15-Jan-2017

297 views

Category:

Education


6 download

TRANSCRIPT

Page 1: المحاضرة الثامنة: تراكيب البيانات الطابور

using Java

2015

Data Structure Prepared by: Mahmoud Rafeek Al-farra

in Java

8. Queue

Page 2: المحاضرة الثامنة: تراكيب البيانات الطابور

mfarra.cst.ps www.fb.com/MahmoudRFarra

Contents

Implementation of Queue

Queue and priority queue Interface

Introduction

Implementation of priority Queue

Page 3: المحاضرة الثامنة: تراكيب البيانات الطابور

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.

Page 4: المحاضرة الثامنة: تراكيب البيانات الطابور

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

Page 5: المحاضرة الثامنة: تراكيب البيانات الطابور

Introductionmfarra.cst.ps www.fb.com/MahmoudRFarra

Page 6: المحاضرة الثامنة: تراكيب البيانات الطابور

Queue Interfacemfarra.cst.ps www.fb.com/MahmoudRFarra

Page 7: المحاضرة الثامنة: تراكيب البيانات الطابور

Priority Queue Interfacemfarra.cst.ps www.fb.com/MahmoudRFarra

Page 8: المحاضرة الثامنة: تراكيب البيانات الطابور

Implementation of Queue mfarra.cst.ps www.fb.com/MahmoudRFarra

Exactly as linked list and stack …

Page 9: المحاضرة الثامنة: تراكيب البيانات الطابور

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

Page 10: المحاضرة الثامنة: تراكيب البيانات الطابور

EnQueue Operationmfarra.cst.ps www.fb.com/MahmoudRFarra

Mohamed

GhadeerAli

Rear Front

AhmedNew item

1

2 X

Page 11: المحاضرة الثامنة: تراكيب البيانات الطابور

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++; }

Page 12: المحاضرة الثامنة: تراكيب البيانات الطابور

DeQueue Operationmfarra.cst.ps www.fb.com/MahmoudRFarra

Mohamed

GhadeerAli

Rear Front

Ahmad

current

Page 13: المحاضرة الثامنة: تراكيب البيانات الطابور

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--;} }

Page 14: المحاضرة الثامنة: تراكيب البيانات الطابور

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]

Page 15: المحاضرة الثامنة: تراكيب البيانات الطابور

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