Section7Key 2 - Int numl: sl.popO; int num2 s2.pop ( ) ;...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Int numl: sl.popO; int num2 s2.pop ( ) ; j-f (numl r: num2) same: false; s3.push (numl) ; s3.push (num2) ; l same = same && s1 . isEmpty ( ) && s2 . isEmpty ( ) ; while ( ! s3. isEmpty ){ s2 .push (s3.pop ); .push (s3.pop ); JI ) return ) 5. One possible same; solution appears below. public void collapse (Stack<Integer> static s) { q : new LinkedQueue <I ntege r> Queue<Integer> ( ! s. isEmpty o while q.enqueue(s.pop )); (!q.isEmptyo while s.push (q.dequeue O ) (!s.isEmptyO) while q.enqueue(s.popO)t while lq. size o s . push (q. dequeue ( ) + q.dequeue O ); (!q.isEmptyO) if s.push (q.dequeue O ) o; ...
View Full Document

Ask a homework question - tutors are online