#include<bits/stdc++.h>
using namespace std;
//BST二叉数
struct node{
int data;
node* l;
node* r;
};
node* newnode(int x){
node* tp = new node;
tp->data=x;
tp->l=NULL;
tp->r=NULL;
return tp;
}
node* insert(node* p, int x){
if(p==NULL) p=newnode(x);
else if(x <= p->data){
p->l = insert(p->l, x);
}else{
p->r = insert(p->r, x);
}
return p;
}
bool serch(node* p, int x){
if(p==NULL) return 0;
else if(p->data == x) return 1;
else if(x<=p->data) return serch(p->l, x);
else return serch(p->r, x);
}
int findmin(node* p){
if(p==NULL){
cout<<"wa"<<endl; return -1;
}else{
while(p->l != NULL){
p = p->l;
}
}
return p->data;
}
int findheight(node* p){//树的最大高度,最远根节点到root边数;
if(p==NULL) return -1;
else return max(findheight(p->l), findheight(p->r))+1;
}
//遍历算法
void bfs(node* p){
if(p==NULL) return;
queue<node* > q;
q.push(p);
while(!q.empty()){
node* tp =q.front();
cout<<tp->data<<' ';
if(tp->l!=NULL) q.push(tp->l);
if(tp->r!=NULL) q.push(tp->r);
q.pop();
}
return;
}
void dfs(node* p){
//if(p==NULL) return;
cout<<p->data<<' ';
if(p->l !=NULL)
dfs(p->l);
if(p->r !=NULL)
dfs(p->r);
}
int main(){
node* a=NULL;
a = insert(a, 50);
a = insert(a, 40);
a = insert(a, 60);
dfs(a);
return 0;
}
#include<bits/stdc++.h>
using namespace std;
//网络爬虫==图的遍历
//有向图,权重图
// class edge{
// string st;
// string ed;
// int w;
// };
//邻接矩阵表示//图稀疏时用
// string s[10];
// int graph[10][10];
//邻接表表示,用vector或者bst
string id[10];//把图中点转为id使用
struct node{
int next;
int w;
};
vector<node> a[10];//邻接表存每个点指向
vector<node>* s[10];//每个点对应的邻接表