l04-recursive-lists

l04-recursive-lists - CS112: Data Structures Lecture 04...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 4 CS112: Data Structures CS112: Data Structures Lecture 04 Recursion on lists
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 2 Lecture 4 Review: Dummy Headers Review: Dummy Headers Problem: In a simple linked list there are two different kinds of place we can have a pointer to a Node Insert-at-head and insert-after-node require different code people Anne Bob
Background image of page 2
CS112: Slides for Prof. Steinberg ʼ s lecture 3 Lecture 4 Review: Dummy Headers Review: Dummy Headers Solution: add an extra “dummy” Node to point to the first real Node in the list people Anne Bob people Anne Bob Bob
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 4 Lecture 4 Review: Review: Iterators Iterators Abstract data type: a container E.g. array or linked list Can do mostly the same things with them, e.g. insert. delete One of the things I want to do is go through the data items one by one
Background image of page 4
CS112: Slides for Prof. Steinberg ʼ s lecture 5 Lecture 4 Solution Solution Methods you can use to build the loop hasNext getNext State: an object Represents a particular instance of iteration Initialized by new
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 6 Lecture 4 Abstract List Traversal Abstract List Traversal while (list.hasNext()) { print(list.getNext().data); } list could be an Array: hasNext() { return (i != list.length) } getNext() { i++; return list[i]; }
Background image of page 6
CS112: Slides for Prof. Steinberg ʼ s lecture 7 Lecture 4 Abstract List Traversal Abstract List Traversal while (list.hasNext()) { print(list.getNext().data); } list could be a LinkedList: hasNext() { return (curr != null) } getNext() { curr = curr.next; return curr; }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 8 Lecture 4 Iterators Iterators See StringList.java and StringListIterator.java
Background image of page 8
CS112: Slides for Prof. Steinberg ʼ s lecture 9 Lecture 4 Review: Review: Last in first out: Stack First in first out: Queue b c a b c a b c a b c a a b c a b c
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 10 Lecture 4 Operations Operations Queue enqueue, dequeue isEmpty, size clear, remove, removeAll first, next (Enumerator would be better.) Stack same but enqueue, dequeue called push, pop
Background image of page 10
CS112: Slides for Prof. Steinberg ʼ s lecture 11 Lecture 4 Uses of Queues Uses of Queues Printer queue Simulation of real world queues Queue in simulator models line of students. More generally, waiting lists when processing one item creates two more items to process E.g. simulator E.g. family tree
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS112: Slides for Prof. Steinberg ʼ s lecture 12 Lecture 4 Invocation Record Invocation Record Each procedure / method call needs to record values of Parameters Local variables Other things When a procedure starts, space allocated for “invocation record” to store these things.
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 11/01/2011 for the course 198 112 at Rutgers.

Page1 / 77

l04-recursive-lists - CS112: Data Structures Lecture 04...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online