@@ -117,18 +117,18 @@ export default class SelectionSort extends Algorithm {
117
117
addDivisorToAlgorithmBar ( ) ;
118
118
119
119
const minMaxButtonList = addRadioButtonGroupToAlgorithmBar (
120
- [ 'Minimum ' , 'Maximum ' ] ,
121
- 'Min/ Max' ,
120
+ [ 'Maximum ' , 'Minimum ' ] ,
121
+ 'Max/Min ' ,
122
122
) ;
123
123
124
- this . minButton = minMaxButtonList [ 0 ] ;
124
+ this . minButton = minMaxButtonList [ 1 ] ;
125
125
this . minButton . onclick = this . minCallback . bind ( this ) ;
126
126
this . controls . push ( this . minButton ) ;
127
- this . minButton . checked = true ;
128
- this . maxButton = minMaxButtonList [ 1 ] ;
127
+ this . maxButton = minMaxButtonList [ 0 ] ;
129
128
this . maxButton . onclick = this . maxCallback . bind ( this ) ;
130
129
this . controls . push ( this . maxButton ) ;
131
- this . isMin = true ;
130
+ this . maxButton . checked = true ;
131
+ this . isMin = false ;
132
132
}
133
133
134
134
setup ( ) {
@@ -165,14 +165,14 @@ export default class SelectionSort extends Algorithm {
165
165
this . code = [
166
166
[ 'procedure SelectionSort(array):' ] ,
167
167
[ ' length ← length of array' ] ,
168
- [ ' for i ← 0, length do' ] ,
169
- [ ' min ← i' ] ,
170
- [ ' for j ← i + 1, length do' ] ,
171
- [ ' if array[j] < array[min ]' ] ,
172
- [ ' min ← j' ] ,
168
+ [ ' for i ← length - 1, 0 do' ] ,
169
+ [ ' max ← i' ] ,
170
+ [ ' for j ← i - 1, 0 do' ] ,
171
+ [ ' if array[j] > array[max ]' ] ,
172
+ [ ' max ← j' ] ,
173
173
[ ' end if' ] ,
174
174
[ ' end for' ] ,
175
- [ ' swap array[min ], array[i]' ] ,
175
+ [ ' swap array[max ], array[i]' ] ,
176
176
[ ' end for' ] ,
177
177
[ 'end procedure' ] ,
178
178
] ;
@@ -198,13 +198,13 @@ export default class SelectionSort extends Algorithm {
198
198
this . swapCountID = this . nextIndex ++ ;
199
199
this . swapCount = 0 ;
200
200
this . codeID = this . addCodeToCanvasBase ( this . code , CODE_START_X , CODE_START_Y ) ;
201
- if ( ! this . isMin ) {
202
- this . cmd ( act . setText , this . codeID [ 2 ] [ 0 ] , ' for i ← length - 1, 0 do' ) ;
203
- this . cmd ( act . setText , this . codeID [ 3 ] [ 0 ] , ' max ← i' ) ;
204
- this . cmd ( act . setText , this . codeID [ 4 ] [ 0 ] , ' for j ← i - 1, 0 do' ) ;
205
- this . cmd ( act . setText , this . codeID [ 5 ] [ 0 ] , ' if array[j] > array[max ]' ) ;
206
- this . cmd ( act . setText , this . codeID [ 5 ] [ 0 ] , ' max ← j' ) ;
207
- this . cmd ( act . setText , this . codeID [ 9 ] [ 0 ] , ' swap array[max ], array[i]' ) ;
201
+ if ( this . isMin ) {
202
+ this . cmd ( act . setText , this . codeID [ 2 ] [ 0 ] , ' for i ← 0, length do' ) ;
203
+ this . cmd ( act . setText , this . codeID [ 3 ] [ 0 ] , ' min ← i' ) ;
204
+ this . cmd ( act . setText , this . codeID [ 4 ] [ 0 ] , ' for j ← i + 1, length do' ) ;
205
+ this . cmd ( act . setText , this . codeID [ 5 ] [ 0 ] , ' if array[j] < array[min ]' ) ;
206
+ this . cmd ( act . setText , this . codeID [ 5 ] [ 0 ] , ' min ← j' ) ;
207
+ this . cmd ( act . setText , this . codeID [ 9 ] [ 0 ] , ' swap array[min ], array[i]' ) ;
208
208
}
209
209
}
210
210
0 commit comments