1043 - #include<iostream> #include<cctype>...

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

View Full Document Right Arrow Icon
#include<iostream> #include<cctype> #include<cstdio> #include<cstdlib> #include<cstring> using namespace std; enum { SIZ = 1004, }; struct Node { char m; int x, y; int w, h; int l, r; static int next; static void reset(); static int getNext(); }; int Node::next; void Node::reset(){ Node::next = 0; } int Node::getNext(){ return Node::next++; } Node tree[SIZ]; char dat[SIZ]; char out[SIZ][SIZ]; int build_tree(){ int p = Node::getNext(); tree[p].m = dat[p]; tree[p].x = tree[p].y = -1; tree[p].l = tree[p].r = -1; if (!isalpha(tree[p].m)){ tree[p].l = build_tree(); tree[p].r = build_tree(); } return p; } void bottom_up_wh(int p){ if (isalpha(tree[p].m)){ tree[p].w = tree[p].h = 2; return; } int l = tree[p].l; int r = tree[p].r; bottom_up_wh(l); bottom_up_wh(r); if (tree[p].m == '-'){ tree[p].w = max(tree[l].w, tree[r].w); tree[p].h = tree[l].h + tree[r].h; } else { tree[p].h = max(tree[l].h, tree[r].h);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
tree[p].w = tree[l].w + tree[r].w; } } void top_down_wh(int p){ if (isalpha(tree[p].m)) { return;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

1043 - #include&lt;iostream&gt; #include&lt;cctype&gt;...

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