随手写了一个树 #include <iostream> using namespace std; struct node1 { int data; node1* left; node1* right; }; node1* root=NULL; int pre_order(node1* root) { if (root!=NULL) { cout<<root->data<<endl; pre_order(root->left); pre_order(root->right); } return 0; } int mid_order(node1* root) { if(root!=NULL) { mid_order(root->left); cout<<root->data<<endl; mid_order(root->right); } return 0; } int last_order(node1* root) { if (root!=NULL) { last_order(root->left); last_order(root->right); cout<<root->data<<endl; } return 0; } int main() { node1 node[6]; root=new node1; root->data=0; for (int i=0;i<6;i++) { node[i].data=i+1; node[i].left=NULL; node[i].right=NULL; } root->left=&node[0]; root->right=&node[1]; node[0].left=&node[2]; node[0].right=&node[3]; node[1].left=&node[4]; node[1].right=&node[5]; pre_order(root); cout<<"this is the mid_order: "<<endl; mid_order(root); cout<<"this is the last_order: "<<endl; last_order(root); return 0; } 本来很简单的东西,就是看一下理解数据结构是否正确,但在调试的时候问题出来了 如果先调试的话 编译无论如何都通不过而且指明 root->data=0;错误 但如果直接生成的话问题就不会产生,奇怪!