大佬看看这题代码(C++)
死循环了!!!!!!!!
OTZ
#include<iostream>
using namespace std;
int sz[1000000][2];
struct node
{
node *left,*right;
int val;
}head;
void build(node *p,int i)
{
p->val=i+1;
cout<<p->val;
if(sz[i][0]!=0)
{
node *left;
left=new node;
build(left->left,sz[i][0]);
}
else
p->left=NULL;
if(sz[i][1]!=0)
{
node *right;
right=new node;
build(right->right,sz[i][1]);
}
else
p->right=NULL;
}
void print_lr(node *p)
{
cout<<p->val<<" ";
if(p->left)
print_lr(p->left);
if(p->right)
print_lr(p->right);
}
void printl_r(node *p)
{
if(p->left)
print_lr(p->left);
cout<<p->val<<" ";
if(p->right)
print_lr(p->right);
}
void printlr_(node *p)
{
if(p->left)
print_lr(p->left);
if(p->right)
print_lr(p->right);
cout<<p->val<<" ";
}
int main()
{
int n;
cin>>n;
head.val=1;
for(int i=0;i<n;i++)
cin>>sz[i][0]>>sz[i][1];
build(&head,0);
print_lr(&head);
cout<<endl;
printl_r(&head);
cout<<endl;
printlr_(&head);
return 0;
}
OTZ OTZ OTZ OTZ OTZ OTZ OTZ OTZ OTZ OTZ