質問するログイン新規登録

質問編集履歴

3

不正な削除の対応

2017/12/26 08:10

投稿

cgengo
cgengo

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,1 +1,49 @@
1
+ C言語
2
+ コード
3
+ #include<stdio.h>
4
+ #include<stdlib.h>
5
+ char buf[128];
6
+
7
+ struct student {int id; char name[32]; int score; };
8
+ typedef struct student datatype;
9
+ struct node{ datatype data; struct node *left,*right; };
10
+
11
+ struct node* get_tree(){
12
+ struct node *t;
13
+ if(fgets(buf,sizeof(buf),stdin)==NULL||buf[0]=='.')
14
+ return NULL;
15
+ else{
16
+ t=(struct node*)malloc(sizeof(struct node));
17
+ sscanf(buf,"%d,%[^,],%d",&t->data.id,t->data.name,&t->data.score);
18
+ t->left=get_tree();
19
+ t->right=get_tree();
20
+ return t;
21
+ }
22
+ }
23
+
24
+ struct node* bst_insert(struct node *t,struct student d){
25
+ /*ここが分からない*/
26
+ }
27
+
28
+ void print_bst(struct node *t){
29
+ if(t==NULL){
30
+ printf(".");
31
+ }else{
32
+ printf("%d,%s,%d",t->data.id,t->data.name,t->data.score);
33
+ print_bst(t->left);
34
+ print_bst(t->right);
35
+ }
36
+ }
37
+ int main(){
38
+ struct node *t=get_tree();
39
+ struct student d;
1
- 解決しました。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
40
+ scanf("%d,%[^,],%d ",&d.id,d.name,&d.score);
41
+ t=bst_insert(t,d);
42
+ print_bst(t);
43
+ return 0;
44
+ }
45
+
46
+ ͜この分からないとなっているところを埋めてほしいです。考えてもなかなかできないです。
47
+ ちなみにこのbst_insert関数は構造体nodeのアドレスtのさす節点を根とする二分探索木に構造体studentの値dをメンバdataとする節点を追加し得られた二分探索木の根の接点のアドレスを返す関数。
48
+
49
+ どなたかよろしくお願いします。参考にさせていただきたいです。

2

2017/12/26 08:10

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,49 +1,1 @@
1
- C言語
2
- コード
3
- #include<stdio.h>
4
- #include<stdlib.h>
5
- char buf[128];
6
-
7
- struct student {int id; char name[32]; int score; };
8
- typedef struct student datatype;
9
- struct node{ datatype data; struct node *left,*right; };
10
-
11
- struct node* get_tree(){
12
- struct node *t;
13
- if(fgets(buf,sizeof(buf),stdin)==NULL||buf[0]=='.')
14
- return NULL;
15
- else{
16
- t=(struct node*)malloc(sizeof(struct node));
17
- sscanf(buf,"%d,%[^,],%d",&t->data.id,t->data.name,&t->data.score);
18
- t->left=get_tree();
19
- t->right=get_tree();
20
- return t;
21
- }
22
- }
23
-
24
- struct node* bst_insert(struct node *t,struct student d){
25
- /*ここが分からない*/
26
- }
27
-
28
- void print_bst(struct node *t){
29
- if(t==NULL){
30
- printf(".");
31
- }else{
32
- printf("%d,%s,%d",t->data.id,t->data.name,t->data.score);
33
- print_bst(t->left);
34
- print_bst(t->right);
35
- }
36
- }
37
- int main(){
38
- struct node *t=get_tree();
39
- struct student d;
40
- scanf("%d,%[^,],%d ",&d.id,d.name,&d.score);
1
+ 解決しました。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
41
- t=bst_insert(t,d);
42
- print_bst(t);
43
- return 0;
44
- }
45
-
46
- ͜この分からないとなっているところを埋めてほしいです。考えてもなかなかできないです。
47
- ちなみにこのbst_insert関数は構造体nodeのアドレスtのさす節点を根とする二分探索木に構造体studentの値dをメンバdataとする節点を追加し得られた二分探索木の根の接点のアドレスを返す関数。
48
-
49
- どなたかよろしくお願いします。参考にさせていただきたいです。

1

コードの修正

2017/12/25 13:33

投稿

cgengo
cgengo

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,5 @@
1
+ C言語
2
+ コード
1
3
  #include<stdio.h>
2
4
  #include<stdlib.h>
3
5
  char buf[128];