65,187
社区成员




#include<stdlib.h>
#include<stdio.h>
struct info
{
int num;
struct info *l;
struct info *r;
};
void deep(struct info *p)
{
if(p!=NULL)
{
printf("%d",p->num);
if(p->l)
{
printf(" ");
deep(p->l);
}
if(p->r)
{
printf(" ");
deep(p->r);
}
}
}
main()
{
int c,n,root,a,b,i;
struct info t[25];
scanf("%d",&c);
while(c--)
{
for(i=0;i<25;i++)
{
t[i].num=i;
t[i].l=NULL;
t[i].r=NULL;
}
scanf("%d",&n);
scanf("%d",&root);
n--;
while(n--)
{
scanf("%d %d %d",&a,&b,&c);
if(c==0)
{
t[a].l=&t[b];
}
else
t[a].r=&t[b];
}
struct info *q=&t[root];
deep(q);
printf("\n");
}
// system("pause");
}
#include<stdlib.h>
#include<stdio.h>
typedef struct node
{
int num;
struct node *left;
struct node *right;
}node, *nodelist;
void deep(node *N)
{
if (N != NULL)
{
printf("%d", N->num);
if (N->left)
{
printf(" ");
deep(N->left);
}
if (N->right)
{
printf(" ");
deep(N->right);
}
}
}
main()
{
int t, n, r;
int a, b, c;
int i;
node tree[25];
int top;
scanf("%d", &t);
while (t--)
{
for (i = 0; i < 25; i++)
{
tree[i].num = i;
tree[i].left = tree[i].right =NULL;
}
scanf("%d", &n);
scanf("%d", &r);
n--;
while (n--)
{
scanf("%d %d %d", &a, &b, &c);
if (c)
tree[a].right = &tree[b];
else
tree[a].left = &tree[b];
}
nodelist p = &tree[r];
deep(p);
printf("\n");
}
// system("pause");
}