#include <stdio.h>
#include <stdlib.h>
 
typedef struct{
    int key;
    int left;
    int right;
} Node;
 
void insert(Node*, int, int);
void print1(Node*, int);
void print2(Node*, int);
 
int main()
{
    char s[10];
    Node *t;
    int m;
    int a;
    int i;
 
    scanf("%d", &m);
    t=(Node*)malloc(sizeof(Node)*m);
 
    int count=0;
    for(i=0; i<m; i++){
        scanf("%s", &s);
        if(s[0]=='i'){ scanf("%d", &a); insert(t, count, a); count++; }
        if(s[0]=='p'){
            if(count>0) print1(t, 0);
            printf("\n");
            if(count>0) print2(t, 0);
            printf("\n");
        }
    }
     
    return 0;
 
}
 
void print1(Node *t, int p)
{
    if(t[p].left>=0) print1(t, t[p].left);
    printf(" %d", t[p].key);
    if(t[p].right>=0) print1(t, t[p].right);
}
 
void print2(Node *t, int p)
{
    printf(" %d", t[p].key);
    if(t[p].left>=0) print2(t, t[p].left);
    if(t[p].right>=0) print2(t, t[p].right);
}
 
void insert(Node *t, int count, int z)
{
    int x=0, y;
    if(count<1) x=-1;
 
    t[count].key = z;
    t[count].left = -1;
    t[count].right= -1;
 
    while(x>=0){
        y = x; // ????????¨????
        if(z < t[x].key)
            x = t[x].left; // ??????????????§????
        else
            x = t[x].right; // ??????????????§????
    }
 
    if(count<1){}
    else if(z < t[y].key){
        t[y].left = count; // z ??? y ?????????????????????
    }
    else {
        t[y].right = count; // z ??? y ?????????????????????
    }
}

Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 4/4	C	CPU: 00.27 sec	Memory: 6464 KB	Length: 1374 B	2015-12-12 10:17	2015-12-12 10:17
Results for testcases
Case #	Verdict	CPU Time	Memory	In	Out	Case Name
Case #1:	: Accepted	00.00 sec	596 KB	103 B	50 B	test_case_1
Case #2:	: Accepted	00.00 sec	600 KB	161 B	134 B	test_case_2
Case #3:	: Accepted	00.00 sec	612 KB	10904 B	7788 B	test_case_3
Case #4:	: Accepted	00.27 sec	6464 KB	6888908 B	6777792 B	test_case_4

< prev |	1	/	4	| next >	 		 : Accepted        00.00 sec        596 KB
 
Judge Input #1 ( in1.txt | 103 B)		Judge Output #1 ( out1.txt | 50 B)
11
insert 8
insert 2
insert 3
insert 7
insert 22
insert 1
insert 10
insert 9
insert 15
insert 13
print
 1 2 3 7 8 9 10 13 15 22
 8 2 1 3 7 22 10 9 15 13
Comments
 
 Under Construction.
 
Categories
 
 
Free Tags
 
 