def rev_level_order(r): if r is None: return None q = Queue() s = Stack() q.enqueue(r) while not q.is_empty(): n = q.dequeue() s.push(n) if n.rightChild: q.enqueue(n.rightChild) if n.leftChild: q.enqueue(n.leftChild) while not s.is_empty(): print str(s.pop().value)
def sort(s): r = Stack() while not s.is_empty(): tmp = s.pop() while not r.is_empty() and r.peek() > tmp: s.push(r.pop()) r.push(tmp) return r
from GeneralPractice.DataStructurs.Stack.Stack import Stack def sort(s): r = Stack() while not s.is_empty(): tmp = s.pop() while not r.is_empty() and r.peek() > tmp: s.push(r.pop()) r.push(tmp) return r if __name__ == "__main__": s = Stack() s.push(8) s.push(3) s.push(5) s.push(3) s.push(2) s.push(1) s.push(9) sorted = sort(s) temp = 1