質問編集履歴

3

見出しも追加しました。

2017/10/21 03:00

投稿

tomokon
tomokon

スコア13

test CHANGED
File without changes
test CHANGED
@@ -60,11 +60,11 @@
60
60
 
61
61
  ```
62
62
 
63
-
63
+ ###関連するソースコード
64
64
 
65
65
  ```
66
66
 
67
- ノードの定義や、ノードを作成、リストを表示する関数も付記します。
67
+ ノードの定義や、ノードを作成、リストを表示する関数も付記します。
68
68
 
69
69
  ●ノードの定義
70
70
 

2

問題のあるコードと、関連コードとを分割して表示するようにしました。

2017/10/21 03:00

投稿

tomokon
tomokon

スコア13

test CHANGED
File without changes
test CHANGED
@@ -57,6 +57,12 @@
57
57
  }
58
58
 
59
59
 
60
+
61
+ ```
62
+
63
+
64
+
65
+ ```
60
66
 
61
67
  *ノードの定義や、ノードを作成、リストを表示する関数も付記します。
62
68
 

1

```でソースコードを閉じ、インシデントを表示するようにしました。

2017/10/21 02:58

投稿

tomokon
tomokon

スコア13

test CHANGED
File without changes
test CHANGED
@@ -14,45 +14,47 @@
14
14
 
15
15
  ###該当のソースコード
16
16
 
17
- ```C
18
17
 
18
+
19
+ ```lang-C
20
+
19
- node_t nodeReverse(node_t **ndPtrPtr)
21
+ node_t nodeReverse(node_t **ndPtrPtr)
20
22
 
21
23
  {
22
24
 
23
- int i = 0;
25
+ int i = 0;
24
26
 
25
- node_t *Pro_ptr1;
27
+ node_t *Pro_ptr1; 
26
28
 
27
-   node_t *Pro_ptr2;
29
+ node_t *Pro_ptr2; 
28
30
 
29
- while(*ndPtrPtr != NULL){
31
+ while(*ndPtrPtr != NULL){
30
32
 
31
- if(i == 0){
33
+ if(i == 0){
32
34
 
33
- Pro_ptr1 = *ndPtrPtr;
35
+ Pro_ptr1 = *ndPtrPtr;        
34
36
 
35
- ndPtrPtr = &((*ndPtrPtr) -> next);
37
+ ndPtrPtr = &((*ndPtrPtr) -> next);
36
38
 
37
- Pro_ptr1 -> next = NULL;
39
+ Pro_ptr1 -> next = NULL;
38
40
 
39
- }else if(i != 0){
41
+ }else if(i != 0){
40
42
 
41
- Pro_ptr2 = *ndPtrPtr;
43
+ Pro_ptr2 = *ndPtrPtr;
42
44
 
43
- ndPtrPtr = &((*ndPtrPtr) -> next);
45
+ ndPtrPtr = &((*ndPtrPtr) -> next);
44
46
 
45
- Pro_ptr2 -> next = Pro_ptr1;
47
+ Pro_ptr2 -> next = Pro_ptr1;        
46
48
 
47
- Pro_ptr1 = Pro_ptr2;
49
+ Pro_ptr1 = Pro_ptr2;
48
50
 
49
- }
51
+ }   
50
52
 
51
- i++;
53
+ i++;
52
54
 
53
55
  }
54
56
 
55
- }
57
+ }
56
58
 
57
59
 
58
60
 
@@ -60,105 +62,101 @@
60
62
 
61
63
  ●ノードの定義
62
64
 
63
- typedef int data_t;
65
+ typedef int data_t;
64
66
 
65
-
66
-
67
- typedef struct nodetag
67
+ typedef struct nodetag
68
68
 
69
69
  {
70
70
 
71
- data_t data;
71
+ data_t data;
72
72
 
73
- struct nodetag *next;
73
+ struct nodetag *next;
74
74
 
75
- }node_t;
75
+ }node_t;
76
76
 
77
77
 
78
78
 
79
79
  ●ノードの作成
80
80
 
81
- node_t *nodeNew(data_t dt, node_t *nxt)
81
+ node_t *nodeNew(data_t dt, node_t *nxt)
82
82
 
83
83
  {
84
84
 
85
- node_t *ndPtr;
85
+ node_t *ndPtr;
86
86
 
87
-
87
+ ndPtr = malloc(sizeof(node_t));
88
88
 
89
- ndPtr = malloc(sizeof(node_t));
89
+ if(ndPtr == NULL){
90
90
 
91
- if(ndPtr == NULL){
92
-
93
- return NULL;
91
+ return NULL;
94
92
 
95
93
  }else{
96
94
 
97
- ndPtr -> data = dt;
95
+ ndPtr -> data = dt;
98
96
 
99
- ndPtr -> next = nxt;
97
+ ndPtr -> next = nxt;
100
98
 
101
- return ndPtr;
99
+ return ndPtr;
102
100
 
103
101
  }
104
102
 
105
103
  }
106
104
 
107
-
105
+
108
106
 
109
107
  ●リストにノードを後から加える関数
110
108
 
111
- int nodeAppend(node_t **ndPtrPtr, data_t dt)
109
+ int nodeAppend(node_t **ndPtrPtr, data_t dt)
112
110
 
113
111
  {
114
112
 
115
- node_t *ndPtr;
113
+ node_t *ndPtr;
116
114
 
117
-
115
+ ndPtr = nodeNew(dt, NULL);
118
116
 
119
- ndPtr = nodeNew(dt, NULL);
117
+ if(ndPtr =NULL){
120
118
 
121
- if(ndPtr == NULL){
122
-
123
- return FAILURE;
119
+ return FAILURE;
124
120
 
125
121
  }
126
122
 
127
-
123
+
128
124
 
129
- while(*ndPtrPtr != NULL){
125
+ while(*ndPtrPtr != NULL){
130
126
 
131
- ndPtrPtr = &((*ndPtrPtr) -> next);
127
+ ndPtrPtr = &((*ndPtrPtr) -> next);    
132
128
 
133
129
  }
134
130
 
135
- *ndPtrPtr = ndPtr;
131
+ *ndPtrPtr = ndPtr;
136
132
 
137
- return SUCCESS;
133
+ return SUCCESS;
138
134
 
139
- }
135
+ }
140
136
 
141
137
 
142
138
 
143
139
  ●リストの表示
144
140
 
145
- void listPrint(node_t *ndPtr)
141
+ void listPrint(node_t *ndPtr)
146
142
 
147
143
  {
148
144
 
149
145
  printf("{");
150
146
 
151
- while(ndPtr != NULL){
147
+ while(ndPtr != NULL){
152
148
 
153
- printf("%d", ndPtr -> data);
149
+ printf("%d", ndPtr -> data);
154
150
 
155
- ndPtr = ndPtr -> next;
151
+ ndPtr = ndPtr -> next;
156
152
 
157
153
  }
158
154
 
159
155
  printf("}\n");
160
156
 
161
- }
157
+ }
158
+
159
+ ```
162
160
 
163
161
 
164
162
 
@@ -173,3 +171,11 @@
173
171
  ###補足情報(言語/FW/ツール等のバージョンなど)
174
172
 
175
173
  使用開発環境:BCC Developer 1.2.21
174
+
175
+
176
+
177
+ ###最後に
178
+
179
+ 機能をうまく活用できず、分かりにくい表示で最初投稿してしまいました。
180
+
181
+ 申し訳ありません。