Lecture17LinkedListRecursion

Lecture17LinkedListRecursion - LinkedList Recursion Write a...

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

View Full Document Right Arrow Icon
LinkedList Recursion
Background image of page 1

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

View Full DocumentRight Arrow Icon
Write a recursive version of addLast (use a helper) public void addLast (Object obj ) { if (first == null) { first = new Node (obj,null); return; } addRecursiveHelper (first,obj); }
Background image of page 2
Write a recursive version (use a helper) public void addRecursiveHelper (Node position,Object obj){ if (position.next == null) { // done position.next = new Node (obj,null); return; } addRecursiveHelper( position.next, obj); return; }
Background image of page 3

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

View Full DocumentRight Arrow Icon
Helper public void addRecursiveHelper (Node position,Object obj){ if (position.next == null) { // done position.next = new Node (obj,null); return; } addRecursiveHelper( position.next, obj); return; }
Background image of page 4
isSorted() Assume Node contains int data and you want to know if the list is sorted in ascending order public ____??_______ isSorted() { }
Background image of page 5

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

View Full DocumentRight Arrow Icon
isSorted() if queue is empty, it is sorted if queue contains only one item, it is sorted if position.data > position.next.data, the queue is not sorted
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

Lecture17LinkedListRecursion - LinkedList Recursion Write a...

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

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