-
Notifications
You must be signed in to change notification settings - Fork 0
/
675d.cpp
61 lines (56 loc) · 1.03 KB
/
675d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <iostream>
#include <stdlib.h>
#include <vector>
using namespace std;
vector<int> record;
class btree{
public:
int data;
btree* left_son;
btree* right_son;
//root constructor
btree(int no):data(no),left_son(NULL),right_son(NULL){
}
void append(int new_no){
if(new_no>data){
if(right_son==NULL){
btree* new_ptr=new btree(new_no);
right_son=new_ptr;
record.push_back(data);
}
else{
right_son->append(new_no);
}
}
else{
if(left_son==NULL){
btree* new_ptr=new btree(new_no);
left_son=new_ptr;
record.push_back(data);
}
else{
left_son->append(new_no);
}
}
}
};
int main(){
int n;
cin>>n;
int container[n];
for(int i=0;i<n;i++){
cin>>container[i];
}
btree* new_tree=new btree(container[0]);
for(int i=1;i<n;i++){
new_tree->append(container[i]);
}
for(int i=0;i<record.size();i++){
cout<<record[i]<<" ";
}
return 0;
}