-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzhuanzhuanye.c
45 lines (39 loc) · 1 KB
/
zhuanzhuanye.c
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
// 计算一棵二叉树中关键字等于x的结点个数:
// 定义二叉树的结构体和二叉树结点类型的结构体
typedef struct btnode{
struct btnode *left;
struct btnode *right;
int data;
}BTnode;
typedef struct bitree{
struct btnode *root;
}Btree;
// count在main主函数里初始化为0
void Count(Btree *t,int *count,int x){
if(t == NULL){
return;
}
if(t->root->data == x){
count += 1;
}
Count(t->left,&count,x); //因为把count定义为指针变量,传的是count的地址,所以要加&
Count(t->right,&count,x);
}
//简单选择排序算法
int SelectSort(int a[],int n){
int i,j,small,x;
for(i = 0;i < n;i ++){
small = i;
for(j = i + 1;j < n;j ++){
if(a[small] > a[j]){
small = j;
}
}
if(small != i){
x = a[i];
a[i] = a[small];
a[small] = x;
}
}
return 0;
}