{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Section7Key 1 - Solution 1 One possible solution to CSE143...

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

View Full Document Right Arrow Icon
Solution to CSE143 Section #7 Problems 1. One possible solution appears be1ow. public void splitStack (Stack<Integer> s) { Queue<Integer> new LinkedQueue<Integer> ( ) ; / / transfer all elements from stack to queue int oldlength s. size (l ; while (!s.isEmptyO) q.enqueue(s.popO); / / transfer negatives from queue to stack for (int i : L; i <: oldlenqth; i++) t int n = q.dequeue0; if(n<0) s.push (n) ; e]- se q. enqueue (n) ; ) / / transfer nonnegatives from queue to stack while (!q.isEmptyO) s.push(q.dequeueO ); 2. One possibLe solution appears below. public void stutter (Stackclnteger> s) { Queue<Integer> q : new LinkedQueue<Integer> O; whil-e (!s.isEmptyO) q.enqueue(s.popO); while(!q.isEmptyO ) s.push(q.dequeueO); while (!s.isEmptyO) q.enqueue(s.popO);
Background image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}