l04-recursive-lists

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

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

CS112: Slides for Prof. Steinberg ʼ s lecture 1 Lecture 4 CS112: Data Structures CS112: Data Structures Lecture 04 Recursion on lists

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

View Full Document
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
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

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

View Full Document
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
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

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

View Full Document
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]; }
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; }

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

View Full Document
CS112: Slides for Prof. Steinberg ʼ s lecture 8 Lecture 4 Iterators Iterators See StringList.java and StringListIterator.java
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

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

View Full Document
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
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

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

View Full Document
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.
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
Ask a homework question - tutors are online