# Copyright David Abrahams 2006. Distributed under the Boost # Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) class frame: def __init__(self, level): self.level = (level + 3)/4 self.children = 0 def tree4(n): stack = [frame(n)] i = 0 while stack: top = stack[-1] if top.children == 4 or i == n: print '>', stack.pop() else: if top.children == 0: print 'mpl::and<', else: print ',', top.children += 1 if top.level == 1 or i == n - 1: print 'p%s'%i, i += 1 else: stack.append(frame(top.level)) print for x in range(1,30): print '%s:\t'%x, tree4(x)