def run(self): DRIVER.simulate_program_entry('straitsort', 33) DRIVER.simulate_statement(34, sys._getframe()) _straightsort = self.straightsort(stlist) DRIVER.simulate_function_return() DRIVER.simulate_statement(34, sys._getframe()) _straightsort DRIVER.simulate_statement(35, sys._getframe())
def run(self): DRIVER.simulate_program_entry('hanoi', 27) DRIVER.simulate_statement(28, sys._getframe()) _hanoi = self.hanoi(n, x, y, z) DRIVER.simulate_function_return() DRIVER.simulate_statement(28, sys._getframe()) _hanoi DRIVER.simulate_statement(29, sys._getframe())
def move_node(self, x, n, y): DRIVER.simulate_function_call('move_node', 21, sys._getframe()) x.frame = sys._getframe() n = n.clone() n.declare() y.frame = sys._getframe() result = None DRIVER.simulate_statement(22, sys._getframe()) DRIVER.simulate_statement(23, sys._getframe()) x[n - Integer(1)].assign(None) DRIVER.simulate_statement(24, sys._getframe()) y[n - Integer(1)].assign(n) DRIVER.simulate_statement(25, sys._getframe()) x.frame = sys._getframe(1) n.destroy() y.frame = sys._getframe(1) return result
def visit(self, bt): DRIVER.simulate_function_call('visit', 17, sys._getframe()) bt = bt.clone() bt.declare() result = None DRIVER.simulate_statement(18, sys._getframe()) DRIVER.simulate_statement(19, sys._getframe()) bt.get()['value'].active() DRIVER.simulate_statement(20, sys._getframe()) bt.destroy() return result
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 run(self): DRIVER.simulate_program_entry('inorder', 23) DRIVER.simulate_statement(24, sys._getframe()) root.assign(Pointer(bintree)) DRIVER.simulate_statement(25, sys._getframe()) _inorder = self.inorder(root) DRIVER.simulate_function_return() DRIVER.simulate_statement(25, sys._getframe()) _inorder DRIVER.simulate_statement(26, sys._getframe())
def inorder(self, bt): DRIVER.simulate_function_call('inorder', 7, sys._getframe()) bt = bt.clone() bt.declare() result = None DRIVER.simulate_statement(8, sys._getframe()) DRIVER.simulate_statement(9, sys._getframe()) if bt != Pointer(): DRIVER.simulate_statement(11, sys._getframe()) _inorder = self.inorder(bt.get()['lchild']) DRIVER.simulate_function_return() DRIVER.simulate_statement(11, sys._getframe()) _inorder DRIVER.simulate_statement(12, sys._getframe()) _visit = self.visit(bt) DRIVER.simulate_function_return() DRIVER.simulate_statement(12, sys._getframe()) _visit DRIVER.simulate_statement(13, sys._getframe()) _inorder = self.inorder(bt.get()['rchild']) DRIVER.simulate_function_return() DRIVER.simulate_statement(13, sys._getframe()) _inorder DRIVER.simulate_statement(15, sys._getframe()) bt.destroy() return result
def qksort(self, r, s, t): DRIVER.simulate_function_call('qksort', 8, sys._getframe()) r.frame = sys._getframe() s = s.clone() s.declare() t = t.clone() t.declare() result = None k = Indexpointer() k.declare() DRIVER.simulate_statement(11, sys._getframe()) DRIVER.simulate_statement(12, sys._getframe()) k.assign(Pointer(r)) DRIVER.simulate_statement(13, sys._getframe()) if s < t: DRIVER.simulate_statement(15, sys._getframe()) _qkpass = self.qkpass(r, s, t, k) DRIVER.simulate_function_return() DRIVER.simulate_statement(15, sys._getframe()) _qkpass DRIVER.simulate_statement(16, sys._getframe()) _qksort = self.qksort(r, s, k - Integer(1)) DRIVER.simulate_function_return() DRIVER.simulate_statement(16, sys._getframe()) _qksort DRIVER.simulate_statement(17, sys._getframe()) _qksort = self.qksort(r, k + Integer(1), t) DRIVER.simulate_function_return() DRIVER.simulate_statement(17, sys._getframe()) _qksort DRIVER.simulate_statement(19, sys._getframe()) r.frame = sys._getframe(1) s.destroy() t.destroy() k.destroy() return result
def run(self): DRIVER.simulate_program_entry('postorder', 21) DRIVER.simulate_statement(22, sys._getframe()) root.assign(Pointer(bintree)) DRIVER.simulate_statement(23, sys._getframe()) _postorder = self.postorder(root) DRIVER.simulate_function_return() DRIVER.simulate_statement(23, sys._getframe()) _postorder DRIVER.simulate_statement(24, sys._getframe())
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
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 run(self): DRIVER.simulate_program_entry('mergesort', 54) DRIVER.simulate_statement(55, sys._getframe()) first.assign(Pointer(meglist)) DRIVER.simulate_statement(55, sys._getframe()) last.assign(Pointer(meglist)) DRIVER.simulate_statement(56, sys._getframe()) first.assign(pascal.low(meglist)) DRIVER.simulate_statement(56, sys._getframe()) last.assign(pascal.high(meglist)) DRIVER.simulate_statement(57, sys._getframe()) pascal.setlength(buflist, last - first + Integer(1)) DRIVER.simulate_statement(58, sys._getframe()) _mergesort = self.mergesort(meglist, buflist.get(), first, last) DRIVER.simulate_function_return() DRIVER.simulate_statement(58, sys._getframe()) _mergesort DRIVER.simulate_statement(59, sys._getframe())
def visit(self, bt): DRIVER.simulate_function_call('visit', 15, sys._getframe()) bt = bt.clone() bt.declare() result = None
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 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 hanoi(self, n, x, y, z): DRIVER.simulate_function_call('hanoi', 10, sys._getframe()) n = n.clone() n.declare() x.frame = sys._getframe() y.frame = sys._getframe() z.frame = sys._getframe() result = None DRIVER.simulate_statement(11, sys._getframe()) DRIVER.simulate_statement(12, sys._getframe()) if n == Integer(1): DRIVER.simulate_statement(13, sys._getframe()) _move_node = self.move_node(x, Integer(1), z) DRIVER.simulate_function_return() DRIVER.simulate_statement(13, sys._getframe()) _move_node else: DRIVER.simulate_statement(15, sys._getframe()) _hanoi = self.hanoi(n - Integer(1), x, z, y) DRIVER.simulate_function_return() DRIVER.simulate_statement(15, sys._getframe()) _hanoi DRIVER.simulate_statement(16, sys._getframe()) _move_node = self.move_node(x, n, z) DRIVER.simulate_function_return() DRIVER.simulate_statement(16, sys._getframe()) _move_node DRIVER.simulate_statement(17, sys._getframe()) _hanoi = self.hanoi(n - Integer(1), y, x, z) DRIVER.simulate_function_return() DRIVER.simulate_statement(17, sys._getframe()) _hanoi DRIVER.simulate_statement(19, sys._getframe()) n.destroy() x.frame = sys._getframe(1) y.frame = sys._getframe(1) z.frame = sys._getframe(1) return result
def run(self): DRIVER.simulate_program_entry('quicksort', 43) DRIVER.simulate_statement(44, sys._getframe()) first.assign(Pointer(qklist)) DRIVER.simulate_statement(44, sys._getframe()) last.assign(Pointer(qklist)) DRIVER.simulate_statement(45, sys._getframe()) first.assign(pascal.low(qklist)) DRIVER.simulate_statement(45, sys._getframe()) last.assign(pascal.high(qklist)) DRIVER.simulate_statement(46, sys._getframe()) _qksort = self.qksort(qklist, first, last) DRIVER.simulate_function_return() DRIVER.simulate_statement(46, sys._getframe()) _qksort DRIVER.simulate_statement(47, sys._getframe())