#include "iostream"using namespace std;struct node {int key;node* left;node* right;node(){}node(int x):key(x),left(NULL),right(NULL){}};struct Tree {node* root;Tree():root(NULL){}};void push(node* S,node x){S[0].key++;S[S[0].key]=x;}node* pop(node* S){if (S[0].key==0) {return NULL;}S[0].key--;return &S[S[0].key+1];}void print_tree(Tree* T){node stack[20]={0};node* t=T->root;while (1) {//如果有節點,則一直往下輸出所有的最左邊的結點,同時用棧儲存所有的結點cout<<t->key<<' ';push(stack,*t);if (t->left) {t=t->left;}else{do{//如果結點的右孩子不存在,則一直彈棧,測試上一個結點,//直到找到一個結點,它的右孩子存在為止,則將指標指向它的右孩子,重複外迴圈t=pop(stack);if (t==NULL) {return;}}while (t->right==NULL) ;t=t->right;}}}void main(){node A[11];for(int i=1;i<=10;i++){int key,left,right;cin>>key>>left>>right;A[i].key=key;if (left) {A[i].left=&A[left];}elseA[i].left=NULL;if (right) {A[i].right=&A[right];}elseA[i].right=NULL;}Tree* T=new Tree();T->root=&A[6];print_tree(T);}