280 likes | 398 Views
Queue using an array. .head. .tail. Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0. Add object to rear of list. 1. .head. .tail. Add object to rear of list. 1. 2. .head. .tail.
E N D
.head .tail Pointers head and tail always point to the first empty slot before or after elements in the list. Thus, initially they point to the same slot, say 0.
Add object to rear of list 1 .head .tail
Add object to rear of list 1 2 .head .tail
Add object to rear of list 1 2 3 .head .tail
Add object to rear of list 1 2 3 4 .head .tail
Remove from front 2 3 4 .head .tail 1 .object
Remove from front 3 4 .head .tail 2 .object
Add 3 4 5 .head .tail
Remove 4 5 .head .tail 3 .object
Add 4 5 6 .head .tail
Add 4 7 5 6 .head .tail
Add 4 7 8 5 6 .head .tail
Add 4 7 8 5 6 9 .tail .head
Queue using Circularly Linked List
Circularly linked list .tail
Queue: remove from front _object .tail _object = tail->next->item;
Queue: remove from front Temp _temp _object .tail _temp = tail->next;
Queue: remove from front Temp _temp _object .tail _tail->next = tail->next->next;
Queue: remove from front Temp _temp _object .tail _delete temp;
Queue: remove from front Temp _object .tail _return object;
Queue: remove from front Temp .tail _
Queue: insert at rear Temp .tail _
Queue: insert at rear _cell Temp NULL .tail _cell = new Cell(object);
Queue: insert at rear _cell Temp .tail _cell->next = tail->next;
Queue: insert at rear _cell Temp .tail _tail->next = cell;
Queue: insert at rear _cell Temp .tail _tail = tail->next;