Exam2-3sol - a copy of the value passed from A to parameter x storage for the local variable y 5 public int size if(head == null return 0 int count

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

View Full Document Right Arrow Icon
1. a. O(n^2) O(n) O(n) b. NO, YES, NO, NO, YES, YES c. 6'1" 5'3" 6'1" 5'10" 2. a. extends SimpleArrayList<E> b. public boolean add(E o) { if (!contains(0)) { return super.add(o); } else { return false; } } c. O(n) d. TURE e. overloading 3. a. O(1), O(n), O(1) b. - - c d 2 3 - b c d 1 3 c. To keep all operations are O(1) 4. a. public static LIFOStack<E> copyStack(LIFOStack<E> s) { LIFOStack<E> copy = new ListStack<E>(); FIFOQueue<E> q = new ListQueue<E>(); while (!s.isEmpty()) { copy.push(s.pop()); // reverse } while (!copy.isEmpty()) { q.enqueue(copy.pop()); // store } while(!q.isEmpty()) { int i = q.dequeue(); s.push(i); //reverse copy.push(i); } return copy; } b. to which instruction in A to return
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a copy of the value passed from A to parameter x storage for the local variable y 5. public int size() { if (head == null) return 0; int count = 0; Node<E> current = head; while (current != null) { count++; current = current.next; } return count; } public void add(E element) { Node<E> newNode = new Node<E>(tail, element, null); if (head == null) { head = newNode } else { tail.next = newNode; } tail = newNode; } public E remove() { if (head == null) { throw new NoSuchElementException(); } E toReturn = head.data; head = head.next; if (head == null) { tail = null; } else { head.prev = null; } return toReturn; }...
View Full Document

This document was uploaded on 12/19/2009.

Page1 / 2

Exam2-3sol - a copy of the value passed from A to parameter x storage for the local variable y 5 public int size if(head == null return 0 int count

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

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