質問編集履歴

2

不正な削除への対応

2017/12/25 09:01

投稿

cgengo
cgengo

スコア12

test CHANGED
@@ -1 +1 @@
1
- 頭付き挿入問題(C言語)
1
+ ダミーつの二分探索木の挿入について
test CHANGED
@@ -1 +1,81 @@
1
+ #include<stdio.h>
2
+
3
+ #include<stdlib.h>
4
+
5
+ char buf[128];
6
+
7
+
8
+
9
+ struct student {int id; char name[32]; int score; };
10
+
11
+ typedef struct student datatype;
12
+
13
+ struct node{ datatype data; struct node *left,*right; };
14
+
15
+
16
+
17
+ void bst_insert(struct node *t,struct student d){
18
+
19
+ /*ここが知りたい*/
20
+
21
+ }
22
+
23
+
24
+
25
+ void print_bst_dummy(struct node *t,struct node *dummy){
26
+
27
+ if(t==dummy)
28
+
29
+ printf(".\n");
30
+
31
+ else{
32
+
1
- 解決完了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
33
+ printf("%d,%s,%d\n",t->data.id,t->data.name,t->data.score);
34
+
35
+ print_bst_dummy(t->left,dummy);
36
+
37
+ print_bst_dummy(t->right,dummy);
38
+
39
+ }
40
+
41
+ return;
42
+
43
+ }
44
+
45
+
46
+
47
+ void print_bst(struct node *t){
48
+
49
+ print_bst_dummy(t->right,t->left);
50
+
51
+ return;
52
+
53
+ }
54
+
55
+
56
+
57
+ int main(){
58
+
59
+ struct node *t=get_tree();
60
+
61
+ struct student d;
62
+
63
+ while(fgets(buf,sizeof(buf),stdin)!=NULL){
64
+
65
+ sscanf(buf,"%d,%[^,],%d",&st.id,st.name,&st.score);
66
+
67
+ bst_insert(t,st);
68
+
69
+ }
70
+
71
+ print_bst(t);
72
+
73
+ return 0;
74
+
75
+ }
76
+
77
+
78
+
79
+ こちらも自己解決ができなかったので相談させてもらいます。ここが知りたいの部分の関数埋めをしてほしいです。
80
+
81
+ ちなみにbst_insert関数は構造体nodeのアドレスtの指す節点を根とする二分探索木に構造体studentの値dをメンバdataとする節点を追加し得られた二分探索木の根の節点のアドレスを返す関数である。

1

2017/12/25 09:01

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- ダミーつの二分探索木の挿入について
1
+ 頭付き挿入問題(C言語)
test CHANGED
@@ -1,81 +1 @@
1
- #include<stdio.h>
2
-
3
- #include<stdlib.h>
4
-
5
- char buf[128];
6
-
7
-
8
-
9
- struct student {int id; char name[32]; int score; };
10
-
11
- typedef struct student datatype;
12
-
13
- struct node{ datatype data; struct node *left,*right; };
14
-
15
-
16
-
17
- void bst_insert(struct node *t,struct student d){
18
-
19
- /*ここが知りたい*/
20
-
21
- }
22
-
23
-
24
-
25
- void print_bst_dummy(struct node *t,struct node *dummy){
26
-
27
- if(t==dummy)
28
-
29
- printf(".\n");
30
-
31
- else{
32
-
33
- printf("%d,%s,%d\n",t->data.id,t->data.name,t->data.score);
1
+ 解決完了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
34
-
35
- print_bst_dummy(t->left,dummy);
36
-
37
- print_bst_dummy(t->right,dummy);
38
-
39
- }
40
-
41
- return;
42
-
43
- }
44
-
45
-
46
-
47
- void print_bst(struct node *t){
48
-
49
- print_bst_dummy(t->right,t->left);
50
-
51
- return;
52
-
53
- }
54
-
55
-
56
-
57
- int main(){
58
-
59
- struct node *t=get_tree();
60
-
61
- struct student d;
62
-
63
- while(fgets(buf,sizeof(buf),stdin)!=NULL){
64
-
65
- sscanf(buf,"%d,%[^,],%d",&st.id,st.name,&st.score);
66
-
67
- bst_insert(t,st);
68
-
69
- }
70
-
71
- print_bst(t);
72
-
73
- return 0;
74
-
75
- }
76
-
77
-
78
-
79
- こちらも自己解決ができなかったので相談させてもらいます。ここが知りたいの部分の関数埋めをしてほしいです。
80
-
81
- ちなみにbst_insert関数は構造体nodeのアドレスtの指す節点を根とする二分探索木に構造体studentの値dをメンバdataとする節点を追加し得られた二分探索木の根の節点のアドレスを返す関数である。