1 / 32

Queue and Priority Queue Implementations

Queue and Priority Queue Implementations. Chapter 14. Implementations of the ADT Queue. Like stacks, queues can have Array-based or Link-based implementation. Can also use implementation of ADT list Efficient to implement Might not be most time efficient as possible.

mreis
Download Presentation

Queue and Priority Queue Implementations

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 andPriority QueueImplementations Chapter 14

  2. Implementations of the ADT Queue • Like stacks, queues can have • Array-based or • Link-based implementation. • Can also use implementation of ADT list • Efficient to implement • Might not be most time efficient as possible

  3. An Implementation That Uses the ADT List • FIGURE 14-1 An implementation of the ADT queue that stores its entries in a list

  4. An Implementation That Uses the ADT List • LISTING 14-1 The header file for the class ListQueue

  5. An Implementation That Uses the ADT List • LISTING 14-1 The header file for the class ListQueue

  6. An Implementation That Uses the ADT List • LISTING 14-2 The implementation file for the class ListQueue

  7. An Implementation That Uses the ADT List • LISTING 14-2 The implementation file for the class ListQueue

  8. An Implementation That Uses the ADT List • LISTING 14-2 The implementation file for the class ListQueue

  9. A Link-Based Implementation • Similar to other link-based implementation • One difference … Must be able to remove entries • From front • From back • Requires a pointer to chain’s last node • Called the “tail pointer”

  10. A Link-Based Implementation • FIGURE 14-2 A chain of linked nodes with head and tail pointers

  11. A Link-Based Implementation • LISTING 14-3 The header file for the class LinkedQueue

  12. A Link-Based Implementation • LISTING 14-3 The header file for the class LinkedQueue

  13. A Link-Based Implementation • FIGURE 14-3 Adding an item to a nonempty queue

  14. A Link-Based Implementation • FIGURE 14-5 Removing an item from a queue of more than one item

  15. A Link-Based Implementation • FIGURE 14-5 Removing an item from a queue of more than one item

  16. A Link-Based Implementation • FIGURE 14-5 Removing an item from a queue of more than one item

  17. A Link-Based Implementation • FIGURE 14-6 A circular chain of linked nodes with one external pointer

  18. A Link-Based Implementation • Figure 14-7 A naive array-based implementation of a queue for which rightward drift can cause the queue to appear full

  19. A Link-Based Implementation • Figure 14-8 A circular array as an implementation of a queue

  20. An Array-Based Implementation • FIGURE 14-9 The effect of three consecutive operations on the queue in Figure 14-8

  21. An Array-Based Implementation • Figure1 4-10 front and back as the queue becomes empty and as it becomes full

  22. An Array-Based Implementation • Figure1 4-10 front and back as the queue becomes empty and as it becomes full

  23. An Array-Based Implementation • LISTING 14-4 The header file for the class ArrayQueue

  24. An Array-Based Implementation • Listing 14-5 The implementation file for the class ArrayQueue

  25. An Array-Based Implementation • Listing 14-5 The implementation file for the class ArrayQueue

  26. An Array-Based Implementation • Listing 14-5 The implementation file for the class ArrayQueue

  27. An Array-Based Implementation • Listing 14-5 The implementation file for the class ArrayQueue

  28. An Array-Based Implementation • Figure 14-11 A circular array having one unused location as an implementation of a queue

  29. Comparing Implementations • Issues • Fixed size (array-based) versus dynamic size (link-based) • Reuse of already implemented class saves time

  30. An Implementation of the ADT Priority Queue • LISTING 14-6 A header file for the class SL_PriorityQueue.

  31. An Implementation of the ADT Priority Queue • LISTING 14-6 A header file for the class SL_PriorityQueue.

  32. End Chapter 14

More Related