Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 14: Queue and Priority Queue Implementations

Similar presentations


Presentation on theme: "Chapter 14: Queue and Priority Queue Implementations"— Presentation transcript:

1 Chapter 14: Queue and Priority Queue Implementations
CS Data Structures Mehmet H Gunes Modified from authors’ slides

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 © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

3 An Implementation That Uses the ADT List
An implementation of the ADT queue that stores its entries in a list © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

4 An Implementation That Uses the ADT List
The header file for the class ListQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

5 An Implementation That Uses the ADT List
The header file for the class ListQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

6 An Implementation That Uses the ADT List
The implementation file for the class ListQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

7 An Implementation That Uses the ADT List
The implementation file for the class ListQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

8 An Implementation That Uses the ADT List
The implementation file for the class ListQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

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” © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

10 A Link-Based Implementation
A chain of linked nodes with head and tail pointers © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

11 A Link-Based Implementation
The header file for the class LinkedQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

12 A Link-Based Implementation
The header file for the class LinkedQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

13 A Link-Based Implementation
Adding an item to a nonempty queue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

14 A Link-Based Implementation
Removing an item from a queue of more than one item © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

15 A Link-Based Implementation
Removing an item from a queue of more than one item © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

16 A Link-Based Implementation
A circular chain of linked nodes with one external pointer © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

17

18 An Array-Based Implementation
A naive array-based implementation of a queue for which rightward drift can cause the queue to appear full © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

19 An Array-Based Implementation
A circular array as an implementation of a queue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

20 An Array-Based Implementation
The effect of three consecutive operations on the queue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

21 An Array-Based Implementation
front and back as the queue becomes empty and as it becomes full © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

22 An Array-Based Implementation
front and back as the queue becomes empty and as it becomes full © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

23 An Array-Based Implementation
The header file for the class ArrayQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

24 An Array-Based Implementation
The implementation file for the class ArrayQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

25 An Array-Based Implementation
The implementation file for the class ArrayQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

26 An Array-Based Implementation
The implementation file for the class ArrayQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

27 An Array-Based Implementation
The implementation file for the class ArrayQueue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

28 An Array-Based Implementation
A circular array having one unused location as an implementation of a queue © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

29 Comparing Implementations
Issues Fixed size (array-based) versus dynamic size (link-based) © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

30 An Implementation of the ADT Priority Queue
A header file for the class SL_PriorityQueue. © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

31 An Implementation of the ADT Priority Queue
A header file for the class SL_PriorityQueue. © 2017 Pearson Education, Hoboken, NJ.  All rights reserved

32


Download ppt "Chapter 14: Queue and Priority Queue Implementations"

Similar presentations


Ads by Google