質問編集履歴

3

書式の改善

2016/12/26 06:34

投稿

ccccididid
ccccididid

スコア23

test CHANGED
File without changes
test CHANGED
@@ -22,23 +22,23 @@
22
22
 
23
23
  {
24
24
 
25
- __struct node *p;
25
+ struct node *p;
26
-
26
+
27
- __if (a == NULL)
27
+ if (a == NULL)
28
-
28
+
29
- ____return b;
29
+ return b;
30
-
30
+
31
- __else if (b == NULL)
31
+ else if (b == NULL)
32
-
32
+
33
- ____return a;
33
+ return a;
34
-
34
+
35
- __for (p = a; p->next != NULL; p = p->next)
35
+ for (p = a; p->next != NULL; p = p->next)
36
-
36
+
37
- ____;
37
+ ;
38
-
38
+
39
- __p->next = b;
39
+ p->next = b;
40
-
40
+
41
- __return a;
41
+ return a;
42
42
 
43
43
  }
44
44
 
@@ -50,75 +50,75 @@
50
50
 
51
51
  {
52
52
 
53
- __int pivot;
54
-
55
- __struct node *t;
56
-
57
- __struct node *l_pivot = NULL;
58
-
59
- __struct node *e_pivot = NULL;
60
-
61
- __struct node *r_pivot = NULL;
62
-
63
-
64
-
65
- __if (c == NULL || c->next == NULL)
66
-
67
- ____return c;
68
-
69
-
70
-
71
- __pivot = c->value;
72
-
73
-
74
-
75
- __for (; c != NULL; c = t)
76
-
77
- ____{
78
-
79
- ______t = c->next;
80
-
81
- ______if (c->value < pivot)
82
-
83
- ________{
84
-
85
- __________c->next = l_pivot;
86
-
87
- __________l_pivot = c;
88
-
89
- ________}
90
-
91
- ______else if (c->value == pivot)
92
-
93
- ________{
94
-
95
- __________c->next = e_pivot;
96
-
97
- __________e_pivot = c;
98
-
99
- ________}
100
-
101
- ______else if (c->value > pivot)
102
-
103
- ________{
104
-
105
- __________c->next = r_pivot;
106
-
107
- __________r_pivot = c;
108
-
109
- ________}
110
-
111
- ____}
112
-
113
-
114
-
115
- __l_pivot = quick_sort_list (l_pivot);
116
-
117
- __r_pivot = quick_sort_list (r_pivot);
118
-
119
-
120
-
121
- __return concatante (l_pivot, concatante (e_pivot, r_pivot));
53
+ int pivot;
54
+
55
+ struct node *t;
56
+
57
+ struct node *l_pivot = NULL;
58
+
59
+ struct node *e_pivot = NULL;
60
+
61
+ struct node *r_pivot = NULL;
62
+
63
+
64
+
65
+ if (c == NULL || c->next == NULL)
66
+
67
+ return c;
68
+
69
+
70
+
71
+ pivot = c->value;
72
+
73
+
74
+
75
+ for (; c != NULL; c = t)
76
+
77
+ {
78
+
79
+ t = c->next;
80
+
81
+ if (c->value < pivot)
82
+
83
+ {
84
+
85
+ c->next = l_pivot;
86
+
87
+ l_pivot = c;
88
+
89
+ }
90
+
91
+ else if (c->value == pivot)
92
+
93
+ {
94
+
95
+ c->next = e_pivot;
96
+
97
+ e_pivot = c;
98
+
99
+ }
100
+
101
+ else if (c->value > pivot)
102
+
103
+ {
104
+
105
+ c->next = r_pivot;
106
+
107
+ r_pivot = c;
108
+
109
+ }
110
+
111
+ }
112
+
113
+
114
+
115
+ l_pivot = quick_sort_list (l_pivot);
116
+
117
+ r_pivot = quick_sort_list (r_pivot);
118
+
119
+
120
+
121
+ return concatante (l_pivot, concatante (e_pivot, r_pivot));
122
122
 
123
123
  }
124
124
 
@@ -144,9 +144,9 @@
144
144
 
145
145
  {
146
146
 
147
- __int value;
147
+ int value;
148
-
148
+
149
- __struct node *next;
149
+ struct node *next;
150
150
 
151
151
  };
152
152
 
@@ -158,11 +158,11 @@
158
158
 
159
159
  {
160
160
 
161
- __for (; p != NULL; p = p->next)
161
+ for (; p != NULL; p = p->next)
162
-
162
+
163
- ____printf (" %d", p->value);
163
+ printf (" %d", p->value);
164
-
164
+
165
- __printf ("\n");
165
+ printf ("\n");
166
166
 
167
167
  }
168
168
 
@@ -174,49 +174,49 @@
174
174
 
175
175
  {
176
176
 
177
- __int list[] = { 1, 3, 7, 4, 2, 6, 5 };
177
+ int list[] = { 1, 3, 7, 4, 2, 6, 5 };
178
-
178
+
179
- __struct node *nodes = NULL;
179
+ struct node *nodes = NULL;
180
-
180
+
181
- __int i;
181
+ int i;
182
-
183
-
184
-
182
+
183
+
184
+
185
- __for (i = sizeof list / sizeof list[0] - 1; i >= 0; --i)
185
+ for (i = sizeof list / sizeof list[0] - 1; i >= 0; --i)
186
-
186
+
187
- ____{
187
+ {
188
-
188
+
189
- ______struct node *p = malloc (sizeof *p);
189
+ struct node *p = malloc (sizeof *p);
190
-
190
+
191
- ______if (p == NULL)
191
+ if (p == NULL)
192
-
192
+
193
- ________{
193
+ {
194
-
194
+
195
- __________perror ("malloc");
195
+ perror ("malloc");
196
-
196
+
197
- __________exit (EXIT_FAILURE);
197
+ exit (EXIT_FAILURE);
198
-
198
+
199
- ________}
199
+ }
200
-
200
+
201
- ______p->value = list[i];
201
+ p->value = list[i];
202
-
202
+
203
- ______p->next = nodes;
203
+ p->next = nodes;
204
-
204
+
205
- ______nodes = p;
205
+ nodes = p;
206
-
206
+
207
- ____}
207
+ }
208
-
209
-
210
-
208
+
209
+
210
+
211
- __print_nodes (nodes);
211
+ print_nodes (nodes);
212
-
212
+
213
- __nodes = quick_sort_list (nodes);
213
+ nodes = quick_sort_list (nodes);
214
-
214
+
215
- __print_nodes (nodes);
215
+ print_nodes (nodes);
216
-
217
-
218
-
216
+
217
+
218
+
219
- __exit (EXIT_SUCCESS);
219
+ exit (EXIT_SUCCESS);
220
220
 
221
221
  }
222
222
 

2

文法の修正

2016/12/26 06:34

投稿

ccccididid
ccccididid

スコア23

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,4 @@
1
- 以下のプログラムでわからないところがあります
1
+ ```C言語
2
-
3
-
4
2
 
5
3
  #include <stdio.h>
6
4
 
@@ -10,6 +8,142 @@
10
8
 
11
9
  {
12
10
 
11
+ int value;
12
+
13
+ struct node *next;
14
+
15
+ };
16
+
17
+
18
+
19
+ static struct node *
20
+
21
+ concatante (struct node *a, struct node *b)
22
+
23
+ {
24
+
25
+ __struct node *p;
26
+
27
+ __if (a == NULL)
28
+
29
+ ____return b;
30
+
31
+ __else if (b == NULL)
32
+
33
+ ____return a;
34
+
35
+ __for (p = a; p->next != NULL; p = p->next)
36
+
37
+ ____;
38
+
39
+ __p->next = b;
40
+
41
+ __return a;
42
+
43
+ }
44
+
45
+
46
+
47
+ struct node *
48
+
49
+ quick_sort_list (struct node *c)
50
+
51
+ {
52
+
53
+ __int pivot;
54
+
55
+ __struct node *t;
56
+
57
+ __struct node *l_pivot = NULL;
58
+
59
+ __struct node *e_pivot = NULL;
60
+
61
+ __struct node *r_pivot = NULL;
62
+
63
+
64
+
65
+ __if (c == NULL || c->next == NULL)
66
+
67
+ ____return c;
68
+
69
+
70
+
71
+ __pivot = c->value;
72
+
73
+
74
+
75
+ __for (; c != NULL; c = t)
76
+
77
+ ____{
78
+
79
+ ______t = c->next;
80
+
81
+ ______if (c->value < pivot)
82
+
83
+ ________{
84
+
85
+ __________c->next = l_pivot;
86
+
87
+ __________l_pivot = c;
88
+
89
+ ________}
90
+
91
+ ______else if (c->value == pivot)
92
+
93
+ ________{
94
+
95
+ __________c->next = e_pivot;
96
+
97
+ __________e_pivot = c;
98
+
99
+ ________}
100
+
101
+ ______else if (c->value > pivot)
102
+
103
+ ________{
104
+
105
+ __________c->next = r_pivot;
106
+
107
+ __________r_pivot = c;
108
+
109
+ ________}
110
+
111
+ ____}
112
+
113
+
114
+
115
+ __l_pivot = quick_sort_list (l_pivot);
116
+
117
+ __r_pivot = quick_sort_list (r_pivot);
118
+
119
+
120
+
121
+ __return concatante (l_pivot, concatante (e_pivot, r_pivot));
122
+
123
+ }
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+ #include <stdio.h>
134
+
135
+ #include <stdlib.h>
136
+
137
+
138
+
139
+ struct node *quick_sort_list (struct node *);
140
+
141
+
142
+
143
+ struct node
144
+
145
+ {
146
+
13
147
  __int value;
14
148
 
15
149
  __struct node *next;
@@ -18,198 +152,62 @@
18
152
 
19
153
 
20
154
 
155
+ static void
156
+
21
- static struct node *
157
+ print_nodes (struct node *p)
22
-
23
- concatante (struct node *a, struct node *b)
158
+
24
-
25
- {
159
+ {
26
-
27
- __struct node *p;
160
+
28
-
29
- __if (a == NULL)
30
-
31
- ____return b;
32
-
33
- __else if (b == NULL)
34
-
35
- ____return a;
36
-
37
- __for (p = a; p->next != NULL; p = p->next)
161
+ __for (; p != NULL; p = p->next)
38
-
162
+
39
- ____;
163
+ ____printf (" %d", p->value);
40
-
164
+
41
- __p->next = b;
165
+ __printf ("\n");
42
-
43
- __return a;
166
+
44
-
45
- }
167
+ }
168
+
169
+
170
+
46
-
171
+ int
47
-
48
-
172
+
49
- struct node *
173
+ main ()
50
-
51
- quick_sort_list (struct node *c)
174
+
52
-
53
- {
175
+ {
54
-
55
- __int pivot;
176
+
56
-
57
- __struct node *t;
177
+ __int list[] = { 1, 3, 7, 4, 2, 6, 5 };
58
-
178
+
59
- __struct node *l_pivot = NULL;
179
+ __struct node *nodes = NULL;
60
-
61
- __struct node *e_pivot = NULL;
180
+
62
-
63
- __struct node *r_pivot = NULL;
64
-
65
-
66
-
67
- __if (c == NULL || c->next == NULL)
68
-
69
- ____return c;
181
+ __int i;
70
-
71
-
72
-
73
- __pivot = c->value;
182
+
74
-
75
-
76
-
183
+
184
+
77
- __for (; c != NULL; c = t)
185
+ __for (i = sizeof list / sizeof list[0] - 1; i >= 0; --i)
78
186
 
79
187
  ____{
80
188
 
189
+ ______struct node *p = malloc (sizeof *p);
190
+
81
- ______t = c->next;
191
+ ______if (p == NULL)
82
-
83
- ______if (c->value < pivot)
192
+
84
-
85
- ________{
193
+ ________{
194
+
86
-
195
+ __________perror ("malloc");
196
+
87
- __________c->next = l_pivot;
197
+ __________exit (EXIT_FAILURE);
88
-
89
- __________l_pivot = c;
198
+
90
-
91
- ________}
199
+ ________}
92
-
200
+
93
- ______else if (c->value == pivot)
201
+ ______p->value = list[i];
94
-
95
- ________{
202
+
96
-
97
- __________c->next = e_pivot;
203
+ ______p->next = nodes;
98
-
204
+
99
- __________e_pivot = c;
205
+ ______nodes = p;
100
-
101
- ________}
102
-
103
- ______else if (c->value > pivot)
104
-
105
- ________{
106
-
107
- __________c->next = r_pivot;
108
-
109
- __________r_pivot = c;
110
-
111
- ________}
112
206
 
113
207
  ____}
114
208
 
115
209
 
116
210
 
117
- __l_pivot = quick_sort_list (l_pivot);
118
-
119
- __r_pivot = quick_sort_list (r_pivot);
120
-
121
-
122
-
123
- __return concatante (l_pivot, concatante (e_pivot, r_pivot));
124
-
125
- }
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
- /#include <stdio.h>
136
-
137
- /#include <stdlib.h>
138
-
139
-
140
-
141
- struct node *quick_sort_list (struct node *);
142
-
143
-
144
-
145
- struct node
146
-
147
- {
148
-
149
- __int value;
150
-
151
- __struct node *next;
152
-
153
- };
154
-
155
-
156
-
157
- static void
158
-
159
- print_nodes (struct node *p)
160
-
161
- {
162
-
163
- __for (; p != NULL; p = p->next)
164
-
165
- ____printf (" %d", p->value);
166
-
167
- __printf ("\n");
168
-
169
- }
170
-
171
-
172
-
173
- int
174
-
175
- main ()
176
-
177
- {
178
-
179
- __int list[] = { 1, 3, 7, 4, 2, 6, 5 };
180
-
181
- __struct node *nodes = NULL;
182
-
183
- __int i;
184
-
185
-
186
-
187
- __for (i = sizeof list / sizeof list[0] - 1; i >= 0; --i)
188
-
189
- ____{
190
-
191
- ______struct node *p = malloc (sizeof *p);
192
-
193
- ______if (p == NULL)
194
-
195
- ________{
196
-
197
- __________perror ("malloc");
198
-
199
- __________exit (EXIT_FAILURE);
200
-
201
- ________}
202
-
203
- ______p->value = list[i];
204
-
205
- ______p->next = nodes;
206
-
207
- ______nodes = p;
208
-
209
- ____}
210
-
211
-
212
-
213
211
  __print_nodes (nodes);
214
212
 
215
213
  __nodes = quick_sort_list (nodes);
@@ -222,6 +220,12 @@
222
220
 
223
221
  }
224
222
 
223
+ ```以下のプログラムでわからないところがあります
224
+
225
+
226
+
227
+
228
+
225
229
 
226
230
 
227
231
  クイックソートの際、3つの条件で別々のリストに代入していますが

1

プログラム

2016/12/26 06:29

投稿

ccccididid
ccccididid

スコア23

test CHANGED
File without changes
test CHANGED
@@ -1,5 +1,7 @@
1
1
  以下のプログラムでわからないところがあります
2
2
 
3
+
4
+
3
5
  #include <stdio.h>
4
6
 
5
7
 
@@ -122,17 +124,17 @@
122
124
 
123
125
  }
124
126
 
125
- ==
127
+
126
-
127
-
128
-
129
- 動作確認用。
128
+
130
-
131
- ==
129
+
132
-
130
+
131
+
132
+
133
+
134
+
133
- #include <stdio.h>
135
+ /#include <stdio.h>
134
-
136
+
135
- #include <stdlib.h>
137
+ /#include <stdlib.h>
136
138
 
137
139
 
138
140
 
@@ -220,7 +222,7 @@
220
222
 
221
223
  }
222
224
 
223
- ==
225
+
224
226
 
225
227
  クイックソートの際、3つの条件で別々のリストに代入していますが
226
228