CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
-
Upload
jeffry-wheeler -
Category
Documents
-
view
226 -
download
1
Transcript of CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.
![Page 1: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/1.jpg)
CSS446Spring 2014
Nan Wang
![Page 2: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/2.jpg)
Java Collection Framework◦ Stack◦ Queue & Priority Queue
2
![Page 3: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/3.jpg)
A hierarchy of interface types and classes for collecting objects. Each interface type is implemented by one or more classes.
3
![Page 4: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/4.jpg)
A stack remembers the order of its elements, but it does not allow you to insert elements in every position.
You can add and remove elements only at the top.
4
![Page 5: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/5.jpg)
A stack is a collection of elements with last-in, first-out retrieval (LIFO).
Undo feature in word processor Run-time stack that a processor or virtual
machine keeps to store the values of variable in nested methods.
5
![Page 6: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/6.jpg)
6
![Page 7: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/7.jpg)
7
![Page 8: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/8.jpg)
In a queue, you add items to one end (the tail) and remove them from the other end (the head).
A priority queue is an unordered collection that has an efficient operation for removing the element with the highest priority. (reading assignments)
8
Bus Stop
frontrear
rear rear rear rear
![Page 9: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/9.jpg)
A Queue is a collection of elements with first-in first-out retrieval.
Print queue
9
![Page 10: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/10.jpg)
A priority queue collects elements, each of which has a priority.
Elements are retrieved according to their priority.
New elements can be inserted in any order. Removing an element from a priority queue,
the element with the most urgent priority is retrieved.
10
![Page 11: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/11.jpg)
Because the priority queue needs to be able to tell which element is the smallest, the added elements should belong to a class that implements the Comparable interface!!!
11
![Page 12: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/12.jpg)
12
![Page 13: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/13.jpg)
Java How to Program 9th
Chapter 7 ,8,9,10, 11,18,20 review questions
Big Java Chapter 7-13,15 Review Questions
13
![Page 14: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/14.jpg)
14
![Page 15: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/15.jpg)
15
![Page 16: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/16.jpg)
16
![Page 17: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/17.jpg)
17
![Page 18: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/18.jpg)
18
![Page 19: CSS446 Spring 2014 Nan Wang Java Collection Framework ◦ Stack ◦ Queue & Priority Queue 2.](https://reader034.fdocuments.net/reader034/viewer/2022052702/56649f475503460f94c69862/html5/thumbnails/19.jpg)
19