You are on page 1of 10

QUEUES

SCUD COMP
Queue is a FIFO structure. In a Queue insertion takes place at the
rear end and deletions at the front end.
Insertion in a Queue

null null
Front rear

23 null

500
Front rear Inserting node
500 10

23 10 30 null

500 nptr
10
Algorithm to insert in a linked list
1. Start
2. nptr=new Node(val, null)
3. If rear =null then 2 else 6
4 . front =nptr
5. rear =nptr
6. rear.link=nptr
7. rear=rear.link
8. stop
Front rear
Deleting node
500 10

23 10 30 null

Address address
500 10
Deleting from a linked list
1. Start
2. If front=null then 3 else 4
3. Print “Queue is empty”
4. del=front.data
5. If front=rear then 6 else 8
6. front=null
7. rear=null
8. front=front.link
9. stop
Application of Queues
For implementing any natural FiFO service like telephone
enquiries, reservation requests, traffic flow etc.
Printer queues, Disk queues
For searching in special data structures
For scheduling.
//algorithm to insert in a queue
1. Start
2. Declare an array Q
3. rear=-1,front =-1
4. if(rear=max-1) then 5 else 7
5. Print “over flow”
6. End if
7. if(front=-1) then 8 else 10
8. front=0
9. end if
10.Q[++rear]=i

;
// Algorithm to delete or dequeue from a Q
1. Start
2. if(front=-1 or front> rear) then 3 else 5
3. Print “under flow”
4. end if
5. front++;
6. stop

You might also like