const int MaxSize = 1000;
void preorder(int *tree, int size, int root)
{
if(root >= size)
return;
int lchild = root * 2 + 1, rchild = root * 2 + 2;
printf("%d ", tree[root]);
preorder(tree, size, lchild);
preorder(tree, size, rchild);
}
void main( )
{
int tree[MaxSize], n, i, root = 0;
scanf("%d", &n);
for(i = 0; i < n; i++)
scanf("%d", &tree);
printf("\n");
preorder(tree, n, root);
} |