270 likes | 283 Views
CompSci 105 SS 2005 Principles of Computer Science. Lecture 14: Queues. Lecturer: Santokh Singh. Test Information on Course Web Page. See the “Test and Exams” Section. Please try not to be late for classes. Tail References. What is the advantage of having a “tail”?. Beer. Milk. Wine.
E N D
CompSci 105 SS 2005 Principles of Computer Science Lecture 14: Queues Lecturer: Santokh Singh
Test Information on Course Web Page. • See the “Test and Exams” Section. • Please try not to be late for classes.
Tail References What is the advantage of having a “tail”? Beer Milk Wine head tail Textbook, pp. 186
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
Circular Linked Lists How do you get the first Node here if the external reference “list” shown above references the last Node? – pg 188. Beer Milk Wine list (head) Textbook, pp. 187ff
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
Dummy Head Nodes What is the advantage of having a Dummy Head? Milk Wine head Textbook, pp. 189ff
List ADT Linked List Array
List ADT Linked List Array SortedList ADT Linked List Array
List ADT Linked List Array SortedList ADT Linked List Array Stack ADT Linked List Array List ADT
Stacks Basic ADT Operations Application: Undo Operations Application: Balancing Parenthesis Array Implementation Linked List Implementation Stack ADT implemented with List ADT
Stack ADT • Push • Pop
Stack ADT void createStack ( ) void isEmpty ( ) void push ( Object newItem ) Object pop () void popAll () Object peek () Textbook, p. 252
Stacks Basic ADT Operations Application: Undo Operations Application: Balancing Parenthesis Array Implementation Linked List Implementation Stack ADT implemented with List ADT
Balancing Parenthesis ( a { b ( ) } ) { a [ b ( c ) d ( ) ) ] } Textbook, pp. 254ff
Stacks Basic ADT Operations Application: Undo Operations Application: Balancing Parenthesis Array Implementation Linked List Implementation Stack ADT implemented with List ADT
Array Implementation 0 1 2 3 4 5 6 7 items: 3 5 1 top: 2 Java Code, Textbook, pp. 260ff
Stacks Basic ADT Operations Application: Undo Operations Application: Balancing Parenthesis Array Implementation Linked List Implementation Stack ADT implemented with List ADT
Linked List Implementation 1 3 5 top Java Code, Textbook, pp. 263ff
ADT List Implementation • 1 • 5 • 3 Java Code, Textbook, pp. 263ff
Queues Basic ADT Queue Operations "Circular" Array Implementation Linked List Implementation "Circular" Linked List Implementation Queue ADT implement with List ADT
Queue ADT void createQueue ( ) void isEmpty ( ) void enqueue ( Object newItem ) Object dequeue () void dequeueAll () Object peek () Textbook, p. 299