321-CL1 - object Item p q.Dequeue(p object Queue_Of_Item q1...

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

View Full Document Right Arrow Icon
local_procedure_body Initialize () { self[inserting_rep] = true; } local_procedure_body Partition ( ) /*! ensures q1 * q2 is permutation of #q and for all x: integer where (x is in elements (q1)) (ARE_IN_ORDER(x, p)) and for all x: integer where (x is in elements (q2)) (not ARE_IN_ORDER(x, p)) !*/ { q1.Clear(); q2.Clear(); while (q.Length > 0) { object Item x; q.Dequeue (x); if (Item_Are_In_Order::Are_In_Order (p, x)) { q2.Enqueue(x); } else { q1.Enqueue(x); } } } local_procedure_body Combine ( ) /*! ensures q = #q1 * <#p> * #q2 !*/ { q &= q1; q1.Clear(); q.Enqueue(p); while (q2.Length() > 0) { object Item x; q2.Dequeue(x); q.Enqueue(x); } } local_procedure_body Sort ( ) /*!
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
ensures q is permutation of #q and IS_ORDERED (q) decreases |q| !*/ { if (q.Length() > 1)
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { object Item p; q.Dequeue (p); object Queue_Of_Item q1, q2; Partition (q, p, q1, q2); Sort (q1); Sort (q2); Combine (q, p, q1, q2); } } public: standard_concrete_operations (Sorting_Machine_Kernel_3); procedure_body Insert ( consumes Item& x ) { self[contents_rep].Enqueue(x); } procedure_body Remove_First ( produces Item& x ) { self[contents_rep].Dequeue(x); } procedure_body Remove_Any ( produces Item& x ) { //not sure how to remove any at random //so this is the same as remove first self[contents_rep].Dequeue(x); } procedure_body Change_To_Extraction_Phase () { self[inserting_rep] = false; Sort(self[contents_rep]); } function_body Boolean Is_In_Extraction_Phase () { object Boolean b; b = !(self[inserting_rep]); return b; } function_body Integer Size () { object Integer x; x = self[contents_rep].Length(); return x; }...
View Full Document

{[ snackBarMessage ]}

Page1 / 3

321-CL1 - object Item p q.Dequeue(p object Queue_Of_Item q1...

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

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