321-HW3 - and IS_ORDERED (q2) ensures q is permutation of...

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

View Full Document Right Arrow Icon
1. global_procedure Split ( ); /*! ensures q1 * q2 is permutation of #q and |q2| <= |q1| <= |q2| + 1 !*/ { q1.Clear(); q2.Clear(); q &= q1; object Integer x; x = q1.Length() / 2; if((q1.Length() mod 2) != 0) { x++; } while(q1.Length() > x) { object Integer temp; q1.Dequeue(temp); q2.Enqueue(temp); } } global_procedure Merge ( ); /*! requires IS_ORDERED (q1)
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: and IS_ORDERED (q2) ensures q is permutation of #q1 * #q2 and IS_ORDERED (q) !*/ { q.Clear(); while ((q1.Length() &gt; 0) and (q2.Length() &gt; 0)) { object Integer temp; if (q1[current] &lt; q2[current]) { q1.Dequeue(temp); q.Enqueue(temp); } else { q2.Dequeue(temp); q.Enqueue(temp); } } while (q1.Length() &gt; 0) { object Integer temp; q1.Dequeue(temp); q.Enqueue(temp); } while (q2.Length() &gt; 0) { object Integer temp; q2.Dequeue(temp); q.Enqueue(temp); } }...
View Full Document

This note was uploaded on 02/27/2012 for the course CSE 321 taught by Professor Bucci during the Winter '11 term at Ohio State.

Page1 / 2

321-HW3 - and IS_ORDERED (q2) ensures q is permutation of...

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