Top Banner
Queue using an array
28

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.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 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.

Queue using an array

Page 2: 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.

.head .tail

Pointers head and tail always point to the first empty slot before or afterelements in the list. Thus, initially they point to the same slot, say 0.

Page 3: 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.

.head.tail

Add object to rear of list1

Page 4: 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.

.head.tail

Add object to rear of list1 2

Page 5: 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.

.head.tail

Add object to rear of list1 2 3

Page 6: 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.

.head.tail

Add object to rear of list1 2 3 4

Page 7: 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.

.head .tail

Remove from front

1

2 3 4

.object

Page 8: 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.

.head .tail

Remove from front

2

3 4

.object

Page 9: 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.

.head .tail

Add3 4 5

Page 10: 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.

.head .tail

Remove4 5

3

.object

Page 11: 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.

.head .tail

Add4 5 6

Page 12: 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.

.head .tail

Add4 5 6 7

Page 13: 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.

.head.tail

Add4 5 6 7 8

Page 14: 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.

.tail .head

Add4 5 6 7 89

Page 15: 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.

Queue using Circularly Linked List

Page 16: 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.

.tail

Circularly linked list

Page 17: 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.

.tail

Queue: insert item at rear, remove at front

Page 18: 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.

.tail

Queue: remove from front

_object = tail->next->item;

_object

Page 19: 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.

.tail

Queue: remove from front

_temp = tail->next;

_object

Temp

_temp

Page 20: 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.

.tail

Queue: remove from front

_tail->next = tail->next->next;

_object

Temp

_temp

Page 21: 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.

.tail

Queue: remove from front

_delete temp;

_object

Temp

_temp

Page 22: 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.

.tail

Queue: remove from front

_return object;

_object

Temp

Page 23: 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.

.tail

Queue: remove from front

_

Temp

Page 24: 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.

.tail

Queue: insert at rear

_

Temp

Page 25: 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.

.tail

Queue: insert at rear

_cell = new Cell(object);

Temp

_cell

NULL

Page 26: 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.

.tail

Queue: insert at rear

_cell->next = tail->next;

Temp

_cell

Page 27: 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.

.tail

Queue: insert at rear

_tail->next = cell;

Temp

_cell

Page 28: 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.

.tail

Queue: insert at rear

_tail = tail->next;

Temp

_cell