题目:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define maxn 1111111
using namespace std;
int x;
struct node
{
int data;node* le=nullptr;node* ri=nullptr;void post_print(){
if(!this) return;if(this->le) this->le->post_print();if(this->ri) this->ri->post_print();cout<<this->data<<endl;}
};
int main()
{
int* arr=new int[maxn];node* root=new node;cin>>x;root->data=x;while(cin>>x){
node* record=root;node* rp=nullptr;int flag=-1;while(record!=nullptr){
rp=record;if(x<rp->data){
flag=0;record=record->le;}else{
flag=1;record=record->ri;}}node* temp=new node;temp->data=x;if(flag) rp->ri=temp;else rp->le=temp;}root->post_print();return 0;
}