+ All Categories
Home > Documents > 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

Date post: 13-Dec-2015
Category:
Upload: kenneth-adams
View: 214 times
Download: 0 times
Share this document with a friend
Popular Tags:
27
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science
Transcript
Page 1: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

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.

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.

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.

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.

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.

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.

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.

8

List ADT

Linked List

Array

Page 9: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

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.

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.

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.

12

Undo Operations

Page 13: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

13

Undo Operations

Page 14: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

14

Stack ADT

Page 15: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

15

Stack ADT

• Push

• Pop

Page 16: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

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.

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.

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.

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.

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.

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.

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.

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.

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.

25

Queue

Page 26: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

26

Queue

Page 27: 1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.

27

Queue ADT

void createQueue ( )

void isEmpty ( )

void enqueue ( Object newItem )

Object dequeue ()

void dequeueAll ()

Object peek ()

Textbook, p. 299


Recommended