Dynamically Linked Queues
Steve Paks
Dynamically Linked Queues
• Linked Queue
int MAX_QUEUES 10; /* maximum number of stacks */
Class Queue{
element item;
Queue link;
}
Queue front[MAX_QUEUES], rear[MAX_QUEUES];
Dynamically Linked
Queues(Cont’d)
• Add to the rear of a linked queue
void addq(Element item){
Queue temp = new Queue();
if(IS_FULL(temp)){
print(“The memory is full”);
exit(1);
}
temp.item = item;
temp.link = null;
if(front != null) {
rear.link = temp;
∙∙∙∙ (a)
} else {
front = temp; ∙∙∙∙ (b)
}
rear = temp;
}
Dynamically Linked
Queues(Cont’d)
• Add to the rear of a linked queue(Cont’d)
(a)

item
front

(b)

item
front(=rear=temp)

rear(=temp)
Dynamically Linked
Queues(Cont’d)
• delete from the rear of a linked queue
Element deleteq(){
Queue temp = front; ∙∙∙∙ (a)
Element item;
if(IS_EMPTY(front)){
print(“The queue is empty?”);
exit(1);
}
item = temp.item; ∙∙∙∙ (b)
front = temp.link; ∙∙∙∙ (c)
return item;
}
Dynamically Linked
Queues(Cont’d)
• delete from the rear of a linked queue(Cont’d)
(a)
front(=temp)
(b)

rear

a
front

rear

a
item
(c)

a
front(=temp.link)

rear

Dynamically linked queues