質問編集履歴

1

わかりやすく変更しました。

2022/05/09 15:03

投稿

Red_Bull
Red_Bull

スコア19

test CHANGED
File without changes
test CHANGED
@@ -2,19 +2,28 @@
2
2
  具体的には _prev_ の使い方がわからないです。
3
3
  _next_ は _test.h_ で書いただけで正常に動いているのに対し、_prev_ が動かないのにはどのような理由があるのかを教えていただきたいです。
4
4
 
5
- int list_print_backStation_doublyリストを後ろからprintしたいです。
5
+ int list_print_backでStation_doublyリストを後ろからprintしたいですがプリントされません
6
+ 全体の文章が長くなってしまいすみません。
6
7
 
7
8
  よろしくお願いいたします。
8
9
 
10
+
11
+ ****出力****
12
+ あ(0.0km) い(0.5km) う(1.0km) え(1.5km) お(2.0km)
13
+
14
+
15
+
9
16
  ```test.h
10
- typedef struct station_doubly {
17
+ typedef struct station {
11
18
  char name[60]; //最大20文字
12
19
  float dist;
13
20
  struct station_doubly *next;
14
21
  struct station_doubly *prev;
15
22
  } Station_doubly;
16
23
 
24
+ int list_print(Station_doubly *list);
17
25
  int list_print_back(Station_doubly *list);
26
+ Station_doubly *list_init();
18
27
  ```
19
28
 
20
29
  ```list_print_back.c
@@ -39,3 +48,56 @@
39
48
  return 0;
40
49
  };
41
50
  ```
51
+
52
+ ```list_init.c
53
+ #include<stdio.h>
54
+ #include<stdlib.h>
55
+ #include "test.h"
56
+ Station_doubly *list_init() {
57
+ Station_doubly *list, *pt;
58
+ list = node_create("dummy", 0.0); //ダミーノード用
59
+ pt = list;
60
+ list_insert_doubly(pt, "あ", 0.0);
61
+ pt = pt->next;
62
+ list_insert_doubly(pt, "い", 0.5);
63
+ pt = pt->next;
64
+ list_insert_doubly(pt, "う", 1.0);
65
+ pt = pt->next;
66
+ list_insert_doubly(pt, "え", 1.5);
67
+ pt = pt->next;
68
+ list_insert_doubly(pt, "お", 2.0);
69
+ return list;
70
+ }
71
+ ```
72
+ ```list_print.c
73
+ #include<stdio.h>
74
+ #include<stdlib.h>
75
+ #include "test.h"
76
+ int list_print(Station_doubly *list) {
77
+ Station_doubly *pt;
78
+ pt = list->next;
79
+ if (pt==NULL) printf("NULL");
80
+ while (pt!=NULL) {
81
+ printf("%s(%3.1fkm) ", pt->name, pt->dist);
82
+ pt = pt->next;
83
+ }
84
+ printf("\n");
85
+ return 0;
86
+ };
87
+ ```
88
+
89
+ ```main.c
90
+ #include<stdio.h>
91
+ #include<stdlib.h>
92
+ #include "test.h"
93
+ int main(void){
94
+ int listmax=20;
95
+ Station_doubly *list, *pt;
96
+ list = list_init();
97
+ list_print(list);
98
+ list_print_back(list);
99
+ return 0;
100
+ }
101
+ ```
102
+
103
+