Bedtime Stories 1(Guru Gobind Singh Ji) - Santokh Singh Jagdev.pdf
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
-
Upload
kenneth-adams -
Category
Documents
-
view
215 -
download
0
Transcript of 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
![Page 1: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/1.jpg)
1
Lecture 14: Queues
Lecturer: Santokh Singh
CompSci 105 SS 2005
Principles of Computer Science
![Page 2: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/2.jpg)
2
• Test Information on Course Web Page.
• See the “Test and Exams” Section.
• Please try not to be late for classes.
![Page 3: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/3.jpg)
3
Tail References
Beer Wine Milk
head
Textbook, pp. 186
tail What is the advantage of having a “tail”?
![Page 4: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/4.jpg)
4
Linked Lists
Inserting and Deleting Elements
Implementing the ADT List
Compared to Arrays
Passing Linked Lists as Parameters
Variations of the Linked List
Tail References
Circular Linked Lists
Dummy Head Nodes
![Page 5: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/5.jpg)
5
Circular Linked Lists
Beer Wine Milk
list(head)
Textbook, pp. 187ff
How do you get the first Node here if the external reference “list” shown above references the last Node? – pg 188.
![Page 6: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/6.jpg)
6
Linked Lists
Inserting and Deleting Elements
Implementing the ADT List
Compared to Arrays
Passing Linked Lists as Parameters
Variations of the Linked List
Tail References
Circular Linked Lists
Dummy Head Nodes
![Page 7: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/7.jpg)
7
Dummy Head Nodes
Textbook, pp. 189ff
Wine Milk
head
What is the advantage of having a Dummy Head?
![Page 8: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/8.jpg)
8
List ADT
Linked List
Array
![Page 9: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/9.jpg)
9
List ADT
Linked List
Array
SortedList ADT
Linked List
Array
![Page 10: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/10.jpg)
10
List ADT
Linked List
Array
SortedList ADT
Linked List
Array
Stack ADT
Linked List
ArrayList ADT
![Page 11: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/11.jpg)
11
Stacks
Basic ADT Operations
Application: Undo Operations
Application: Balancing Parenthesis
Array Implementation
Linked List Implementation
Stack ADT implemented with List ADT
![Page 12: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/12.jpg)
12
Undo Operations
![Page 13: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/13.jpg)
13
Undo Operations
![Page 14: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/14.jpg)
14
Stack ADT
![Page 15: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/15.jpg)
15
Stack ADT
• Push
• Pop
![Page 16: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/16.jpg)
16
Stack ADT
void createStack ( )
void isEmpty ( )
void push ( Object newItem )
Object pop ()
void popAll ()
Object peek ()
Textbook, p. 252
![Page 17: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/17.jpg)
17
Stacks
Basic ADT Operations
Application: Undo Operations
Application: Balancing Parenthesis
Array Implementation
Linked List Implementation
Stack ADT implemented with List ADT
![Page 18: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/18.jpg)
18
Balancing Parenthesis
( a { b ( ) } )
{ a [ b ( c ) d ( ) ) ] }
Textbook, pp. 254ff
![Page 19: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/19.jpg)
19
Stacks
Basic ADT Operations
Application: Undo Operations
Application: Balancing Parenthesis
Array Implementation
Linked List Implementation
Stack ADT implemented with List ADT
![Page 20: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/20.jpg)
20
Array Implementation
items: 153
2
top:
0 1 2 3
4 5 6 7
Java Code, Textbook, pp. 260ff
![Page 21: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/21.jpg)
21
Stacks
Basic ADT Operations
Application: Undo Operations
Application: Balancing Parenthesis
Array Implementation
Linked List Implementation
Stack ADT implemented with List ADT
![Page 22: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/22.jpg)
22
Linked List Implementation
1 5 3
top
Java Code, Textbook, pp. 263ff
![Page 23: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/23.jpg)
23
ADT List Implementation
Java Code, Textbook, pp. 263ff
1. 1
2. 5
3. 3
4.
5.
6.
![Page 24: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/24.jpg)
24
Queues
Basic ADT Queue Operations
"Circular" Array Implementation
Linked List Implementation
"Circular" Linked List Implementation
Queue ADT implement with List ADT
![Page 25: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/25.jpg)
25
Queue
![Page 26: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/26.jpg)
26
Queue
![Page 27: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.](https://reader030.fdocuments.us/reader030/viewer/2022032703/56649f4d5503460f94c6e940/html5/thumbnails/27.jpg)
27
Queue ADT
void createQueue ( )
void isEmpty ( )
void enqueue ( Object newItem )
Object dequeue ()
void dequeueAll ()
Object peek ()
Textbook, p. 299