This preview shows page 1. Sign up to view the full content.
Unformatted text preview: .. x2 X1 (with xN at the front) Stack<E> s = new Stack<E>(); while (!q.empty()) s.push(q.dequeue()); while (!s.empty()) q.enqueue(s.pop()); } OPERATION WORST-CASE TIME AVERAGE-CASE TIME constructor O(1) O(1) empty O(1) O(1) size O(1) O(1) push O(N) O(1) pop O(1) O(1) peek O(1) O(1) OPERATION WORST-CASE TIME constructor O(1) empty O(1) size O(1) push O(1) pop O(1) peek O(1) Page 1 of 1 Stacks and Queues Answers 2008/3/27 http://pages.cs.wisc.edu/~cs367-1/topics/Stacks-and-Queues/answers.html...
View Full Document
This note was uploaded on 03/27/2008 for the course CS 367 taught by Professor Marvinsolomon during the Spring '08 term at Wisconsin.
- Spring '08
- Data Structures