Queue using an array
Download
1 / 28

Queue using an array - PowerPoint PPT Presentation


  • 77 Views
  • Uploaded on
  • Presentation posted in: General

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha

Download Presentation

Queue using an array

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


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


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: insert item at rear, remove at front

.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;


ad
  • Login