def straightsort(self, r): DRIVER.simulate_function_call('straightsort', 5, sys._getframe()) r.frame = sys._getframe() result = None n = Integer() n.declare() i = Indexpointer() i.declare() DRIVER.simulate_statement(9, sys._getframe()) DRIVER.simulate_statement(10, sys._getframe()) n.assign(pascal.high(r)) DRIVER.simulate_statement(11, sys._getframe()) i.assign(Pointer(r)) i.assign(Integer(2) - Integer(1)) _for_end = n while True: DRIVER.simulate_statement(12, sys._getframe()) i.assign(i + Integer(1)) if i > _for_end: break DRIVER.simulate_statement(13, sys._getframe()) _straipass = self.straipass(r, i) DRIVER.simulate_function_return() DRIVER.simulate_statement(13, sys._getframe()) _straipass DRIVER.simulate_statement(14, sys._getframe()) r.frame = sys._getframe(1) n.destroy() i.destroy() return result
def mergesort(self, r, r1, s, t): DRIVER.simulate_function_call('mergesort', 8, sys._getframe()) r.frame = sys._getframe() r1.frame = sys._getframe() s = s.clone() s.declare() t = t.clone() t.declare() result = None r2 = Queue() r2.declare() m = Integer() m.declare() DRIVER.simulate_statement(12, sys._getframe()) DRIVER.simulate_statement(13, sys._getframe()) pascal.setlength(r2, t + Integer(1)) DRIVER.simulate_statement(14, sys._getframe()) if s == t: DRIVER.simulate_statement(15, sys._getframe()) r1[s].assign(r[s]) else: DRIVER.simulate_statement(17, sys._getframe()) m.assign(pascal.trunc((s + t) / Integer(2))) DRIVER.simulate_statement(18, sys._getframe()) _mergesort = self.mergesort(r, r2, s, m) DRIVER.simulate_function_return() DRIVER.simulate_statement(18, sys._getframe()) _mergesort DRIVER.simulate_statement(19, sys._getframe()) _mergesort = self.mergesort(r, r2, m + Integer(1), t) DRIVER.simulate_function_return() DRIVER.simulate_statement(19, sys._getframe()) _mergesort DRIVER.simulate_statement(20, sys._getframe()) _merge = self.merge(r2, s, m, t, r1) DRIVER.simulate_function_return() DRIVER.simulate_statement(20, sys._getframe()) _merge DRIVER.simulate_statement(22, sys._getframe()) pascal.dispose(r2) DRIVER.simulate_statement(23, sys._getframe()) r.frame = sys._getframe(1) r1.frame = sys._getframe(1) s.destroy() t.destroy() r2.destroy() m.destroy() return result
def straipass(self, r, i): DRIVER.simulate_function_call('straipass', 16, sys._getframe()) r.frame = sys._getframe() i = i.clone() i.declare() result = None x = Integer() x.declare() j = Indexpointer() j.declare() DRIVER.simulate_statement(20, sys._getframe()) DRIVER.simulate_statement(21, sys._getframe()) j.assign(Pointer(r)) DRIVER.simulate_statement(22, sys._getframe()) r[Integer(0)].assign(r[i]) DRIVER.simulate_statement(23, sys._getframe()) j.assign(i - Integer(1)) DRIVER.simulate_statement(24, sys._getframe()) x.assign(r[i]) DRIVER.simulate_statement(25, sys._getframe()) while x < r[j]: DRIVER.simulate_statement(27, sys._getframe()) r[j + Integer(1)].assign(r[j]) DRIVER.simulate_statement(28, sys._getframe()) j.assign(j - Integer(1)) DRIVER.simulate_statement(30, sys._getframe()) r[j + Integer(1)].assign(r[Integer(0)]) DRIVER.simulate_statement(31, sys._getframe()) r.frame = sys._getframe(1) i.destroy() x.destroy() j.destroy() return result
def qkpass(self, r, s, t, i): DRIVER.simulate_function_call('qkpass', 21, sys._getframe()) r.frame = sys._getframe() s = s.clone() s.declare() t = t.clone() t.declare() i.frame = sys._getframe() result = None j = Integer() j.declare() x = Integer() x.declare() rp = Integer() rp.declare() DRIVER.simulate_statement(26, sys._getframe()) DRIVER.simulate_statement(27, sys._getframe()) i.assign(s) DRIVER.simulate_statement(28, sys._getframe()) j.assign(t) DRIVER.simulate_statement(29, sys._getframe()) rp.assign(r[s]) DRIVER.simulate_statement(30, sys._getframe()) x.assign(r[s]) DRIVER.simulate_statement(31, sys._getframe()) while i < j: DRIVER.simulate_statement(33, sys._getframe()) while i < j and r[j] >= x: DRIVER.simulate_statement(34, sys._getframe()) j.assign(j - Integer(1)) DRIVER.simulate_statement(35, sys._getframe()) r[i].assign(r[j]) DRIVER.simulate_statement(36, sys._getframe()) while i < j and r[i] <= x: DRIVER.simulate_statement(37, sys._getframe()) i.assign(i + Integer(1)) DRIVER.simulate_statement(38, sys._getframe()) r[j].assign(r[i]) DRIVER.simulate_statement(40, sys._getframe()) r[i].assign(rp) DRIVER.simulate_statement(41, sys._getframe()) r.frame = sys._getframe(1) s.destroy() t.destroy() i.frame = sys._getframe(1) j.destroy() x.destroy() rp.destroy() return result
def merge(self, rs, s, m, n, rn): DRIVER.simulate_function_call('merge', 25, sys._getframe()) rs = rs.clone() rs.declare() s = s.clone() s.declare() m = m.clone() m.declare() n = n.clone() n.declare() rn.frame = sys._getframe() result = None i = Indexpointer() i.declare() j = Indexpointer() j.declare() k = Indexpointer() k.declare() ki = Integer() ki.declare() DRIVER.simulate_statement(29, sys._getframe()) DRIVER.simulate_statement(30, sys._getframe()) i.assign(Pointer(rs)) DRIVER.simulate_statement(30, sys._getframe()) j.assign(Pointer(rs)) DRIVER.simulate_statement(30, sys._getframe()) k.assign(Pointer(rs)) DRIVER.simulate_statement(31, sys._getframe()) i.assign(s) DRIVER.simulate_statement(31, sys._getframe()) j.assign(m + Integer(1)) DRIVER.simulate_statement(31, sys._getframe()) k.assign(s - Integer(1)) DRIVER.simulate_statement(32, sys._getframe()) while (i <= m) and (j <= n): DRIVER.simulate_statement(34, sys._getframe()) k.assign(k + Integer(1)) DRIVER.simulate_statement(35, sys._getframe()) if rs[i] <= rs[j]: DRIVER.simulate_statement(37, sys._getframe()) rn[k].assign(rs[i]) DRIVER.simulate_statement(38, sys._getframe()) i.assign(i + Integer(1)) else: DRIVER.simulate_statement(42, sys._getframe()) rn[k].assign(rs[j]) DRIVER.simulate_statement(43, sys._getframe()) j.assign(j + Integer(1)) DRIVER.simulate_statement(46, sys._getframe()) if i <= m: ki.assign(k + Integer(1) - Integer(1)) _for_end = n while True: DRIVER.simulate_statement(47, sys._getframe()) ki.assign(ki + Integer(1)) if ki > _for_end: break DRIVER.simulate_statement(48, sys._getframe()) rn[ki].assign(rs[i + ki - k - Integer(1)]) DRIVER.simulate_statement(49, sys._getframe()) if j <= n: ki.assign(k + Integer(1) - Integer(1)) _for_end = n while True: DRIVER.simulate_statement(50, sys._getframe()) ki.assign(ki + Integer(1)) if ki > _for_end: break DRIVER.simulate_statement(51, sys._getframe()) rn[ki].assign(rs[j + ki - k - Integer(1)]) DRIVER.simulate_statement(52, sys._getframe()) rs.destroy() s.destroy() m.destroy() n.destroy() rn.frame = sys._getframe(1) i.destroy() j.destroy() k.destroy() ki.destroy() return result