1 / 28

Queue using an array

This guide provides a detailed explanation of how to implement a queue using arrays and circular linked lists. It covers the fundamental concepts, including the use of head and tail pointers that indicate the first empty slot in the array. The document illustrates enqueue and dequeue operations, showing how items are added to the rear and removed from the front of the queue. Additionally, it explores the advantages of using a circular linked list for efficient memory management and continuous operations without wasting space.

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Queue using an array

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

  3. Add object to rear of list 1 .head .tail

  4. Add object to rear of list 1 2 .head .tail

  5. Add object to rear of list 1 2 3 .head .tail

  6. Add object to rear of list 1 2 3 4 .head .tail

  7. Remove from front 2 3 4 .head .tail 1 .object

  8. Remove from front 3 4 .head .tail 2 .object

  9. Add 3 4 5 .head .tail

  10. Remove 4 5 .head .tail 3 .object

  11. Add 4 5 6 .head .tail

  12. Add 4 7 5 6 .head .tail

  13. Add 4 7 8 5 6 .head .tail

  14. Add 4 7 8 5 6 9 .tail .head

  15. Queue using Circularly Linked List

  16. Circularly linked list .tail

  17. Queue: insert item at rear, remove at front .tail

  18. Queue: remove from front _object .tail _object = tail->next->item;

  19. Queue: remove from front Temp _temp _object .tail _temp = tail->next;

  20. Queue: remove from front Temp _temp _object .tail _tail->next = tail->next->next;

  21. Queue: remove from front Temp _temp _object .tail _delete temp;

  22. Queue: remove from front Temp _object .tail _return object;

  23. Queue: remove from front Temp .tail _

  24. Queue: insert at rear Temp .tail _

  25. Queue: insert at rear _cell Temp NULL .tail _cell = new Cell(object);

  26. Queue: insert at rear _cell Temp .tail _cell->next = tail->next;

  27. Queue: insert at rear _cell Temp .tail _tail->next = cell;

  28. Queue: insert at rear _cell Temp .tail _tail = tail->next;

More Related