MSc.It :- Ali Abdul Karem Habib Kufa University / mathematics & Science Of Computer QUEUE Contains elements that are inserted and removed according to the first-in-first-out (FIFO) principle . Remove ADD FRONT Rear QUEUES OPERATIONS 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 OPERATIONS ON QUEUES … CONT 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. USING ARRAYS TO IMPLEMENT QUEUES INSERTION ALGORITHM 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 DELETE ALGORITHM 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 APPLICATIONS OF QUEUE 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 TYPES OF QUEUE Linear Queue Circular Double Queue ended Queue Priority Queue CIRCULAR QUEUE 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 . Queue 0 1 2 3 A B C D Front = 0 4 5 6 7 5 6 7 Rear= 3 0 1 2 3 C D Front = 2 0 1 4 Rear= 3 2 3 4 5 6 7 C D E F G H Rear= 7 Front = 2 I Rear= 0 C D E Front = 2 F G H ALGORITHM INSERTION 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 ALGORITHM DELETE 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 DOUBLE END 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. 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 PRIORITY 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. ASSIGNMENT 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