#include<stdio.h>
#include<stdlib.h>
struct BSTreeNode
{
int value;
struct BSTreeNode *left;
struct BSTreeNode *right;
BSTreeNode()
{
left=right=NULL;
}
};
BSTreeNode *head=NULL,*tail=NULL;
void createList(BSTreeNode *cur)
{
cur->left=tail;
if(NULL!=tail)
tail->right=cur;
else
head=cur;
tail=cur;
}
BSTreeNode* visit(BSTreeNode *root)
{
if(NULL!=root)
{
visit(root->left);
createList(root);
visit(root->right);
}
return root;
}
void addNode(BSTreeNode **root,int value)
{
BSTreeNode *p;
if(NULL!=*root)
{
if(value>(*root)->value)
addNode(&((*root)->right),value);
else if(value<(*root)->value)
addNode(&((*root)->left),value);
else
printf("the value:%d is already exist!",value);
}else
{
p=(BSTreeNode *)malloc(sizeof(BSTreeNode));
p->left=p->right=NULL;
p->value=value;
*root=p;
}
}
int main(int argc,char *argv[])
{
freopen("input.txt","r",stdin);
BSTreeNode *root=NULL;
int data,num,i;
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%d",&data);
addNode(&root,data);
}
root=visit(root);
BSTreeNode *cur;
cur=head;
if(cur==NULL)
puts("error!");
else
{
while(NULL!=cur)
{
printf("%d ",cur->value);
cur=cur->right;
}
puts("\n");
}
return 0;
}
#include<stdlib.h>
struct BSTreeNode
{
int value;
struct BSTreeNode *left;
struct BSTreeNode *right;
BSTreeNode()
{
left=right=NULL;
}
};
BSTreeNode *head=NULL,*tail=NULL;
void createList(BSTreeNode *cur)
{
cur->left=tail;
if(NULL!=tail)
tail->right=cur;
else
head=cur;
tail=cur;
}
BSTreeNode* visit(BSTreeNode *root)
{
if(NULL!=root)
{
visit(root->left);
createList(root);
visit(root->right);
}
return root;
}
void addNode(BSTreeNode **root,int value)
{
BSTreeNode *p;
if(NULL!=*root)
{
if(value>(*root)->value)
addNode(&((*root)->right),value);
else if(value<(*root)->value)
addNode(&((*root)->left),value);
else
printf("the value:%d is already exist!",value);
}else
{
p=(BSTreeNode *)malloc(sizeof(BSTreeNode));
p->left=p->right=NULL;
p->value=value;
*root=p;
}
}
int main(int argc,char *argv[])
{
freopen("input.txt","r",stdin);
BSTreeNode *root=NULL;
int data,num,i;
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%d",&data);
addNode(&root,data);
}
root=visit(root);
BSTreeNode *cur;
cur=head;
if(cur==NULL)
puts("error!");
else
{
while(NULL!=cur)
{
printf("%d ",cur->value);
cur=cur->right;
}
puts("\n");
}
return 0;
}