#include #include typedef struct node* link; struct node { int key; link l,r; }; link load(int count) { // Linear-time inorder loading of BST from file int leftCount,rightCount; link work,left; if (count==0) return NULL; leftCount=count/2; rightCount=count-leftCount-1; left=load(leftCount); work=(link) malloc(sizeof(struct node)); work->l=left; scanf("%d",&work->key); work->r=load(rightCount); return work; } void check(link root, int *lastKey) { if (!root) return; check(root->l,lastKey); if (*lastKey >= root->key) { printf("Inorder error %d %d\n",*lastKey,root->key); exit(0); } *lastKey=root->key; check(root->r,lastKey); } void print(link h,int level) { // Print indented tree from right-to-left int i; if (!h) { for (i=0;ir,level+1); for (i=0;ikey); print(h->l,level+1); } int main() { int n; link root; int lastKey=(-999999); scanf("%d",&n); root=load(n); check(root,&lastKey); print(root,0); }