Presentation is loading. Please wait.

Presentation is loading. Please wait.

MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer.

Similar presentations

Presentation on theme: "MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer."— Presentation transcript:

1 MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer

2 Q UEUE Contains elements that are inserted and removed according to the first-in-first-out (FIFO) principle. Rear FRONT ADD Remove

3 Q UEUES O PERATIONS It supports two fundamental methods: INSERT : insert an element at the end of the queue DELETE : remove and return from the queue the element at the front Checking Conditions: Queue Overflow :If rear=maxsize Queue Empty: If front=-1

4 O PERATIONS ON Q UEUES … C ONT The linear array queue has two pointer variables: FRONT, containing location of front element ; and REAR containing location of rear element. The new element will add itself from the 'rear' end, then Queue's 'rear' value increments by one. The element leave the queue from the 'front' end, so queue the Queue's 'front' value increments by one.


6 I NSERTION A LGORITHM This algorithm for Add new element in queue Step1 : Start Step2 : let queue[Size] Step3 : let front=-1, Rear=-1 // Initialization Queue Step4 : if (rear = queue. Size ) Then Step5 : print ( Queue Is Full“Data Is Data Over flow “) Step6 : Else rear=rear+1 Step7 : queue[rear]=item. Step8 : if front = -1 Then Step 9 : Front= 0 Step10: End

7 D ELETE A LGORITHM This algorithm to remove item from queue. Step 1: Start Step 2: if ( front = -1) then Step 3: Print ( “ Queue Is Empty “, “ Data Underflow “) Step 4: else print ( queue[front]) Step 5: if (front=rear ) then Step 6: front = -1, rear=-1 Step 7: Else front =front+1 Step 8: End

8 A PPLICATIONS OF Q UEUE It is used in scheduling the jobs to be processed by the processor. A queue schedules the order of the print files to be printed. A server maintains a queue of the client requests to be processed

9 T YPES O F QUEUE Linear Queue Circular Queue Double ended Queue Priority Queue

10 C IRCULAR Q UEUE A circular queue is a Queue but a particular implementation of a queue. They have a circular structure. There is no space lost. Properties of this type of queue is :- Front pointing to the first item Rear pointing to the last item. When the rear arrived to end of queue make it wrap to first of queue (rear =0), also this with front.

11 ABCD Queue Front = 0 01234567 Rear= 3 CD Front = 2Rear= 3 01234567 CDEFGH Front = 2 01234567 Rear= 7 ICDEFGH Front = 2 Rear= 0

12 A LGORITHM I NSERTION FOR CQ Step 1: Start Step 2: front = -1, Rear =-1 Step 3: rear=rear+1 Step 4: if ( rear=CQ.Size ) then Step 5: Let rear=0 Step 6: if ( rear = front and CQ[rear] Not null ) then Step7: Print (“ Data CQ Is Overflow “ ) Step 8: else CQ[Rear]=item Step 9: End

13 A LGORITHM D ELETE FOR CQ Step 1: Start Step 2: If (front= -1 ) then Step 3: Print( CQ Is Empty ) Step 4: else Print (CQ[front]) Step 5: if ( front = CQ.Size) then Step 6: front =0 Step 7: else front =front+1 Step 8: end

14 D OUBLE E ND QUEUE It is a linear list in which elements are added or removed at either end but not in middle.  a double-ended queue is a data structure it supports the following operations: enq_front, enq_back, deq_front, deq_back.  DeQueue can be represented in two ways they are  1) Input restricted De-Queue :- allows insertions at only one end but allows deletions on both ends of the list.  2) Output-restricted de-queue:- allows deletions at only one end but allows insertions at both ends of the list.

15 Example - We can delete X by F1 and add new element after T by R1 - We can delete T by F2 and add new element after X by R2

16 P RIORITY QUEUE A priority queue is a collection of elements such that each element has been assigned a priority and the order in which elements are deleted and processed comes from the following rules: (1) An element of higher priority is processed before any element of lower priority. (2) Two elements with the same priority are processed according to the order in which they were added to the queue.

17 A SSIGNMENT 5 Write Algorithm to insertion element into queue. Write algorithm to deletion element from queue. Write algorithm to insert element in to CQ. Write algorithm to delete element from CQ. Check the any number is palindrome Or not Using DE-Q

Download ppt "MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer."

Similar presentations

Ads by Google