1
- //merge and quick sort under construction
2
-
3
1
var colors = [
4
2
"one" ,
5
3
"two" ,
@@ -72,9 +70,9 @@ function barChart(data) {
72
70
for ( var i = 0 ; i < 12 ; i ++ )
73
71
document . getElementsByClassName ( "chart" ) [ i ] . innerHTML = chart . outerHTML ;
74
72
}
75
- var countChart = 0 ;
73
+ var countChart = 0 ;
76
74
var modBarChart = ( data , index ) => {
77
- var st = Date . now ( ) ;
75
+ var st = Date . now ( ) ;
78
76
var chart = document . createElement ( "div" ) ;
79
77
80
78
var barchart = document . createElement ( "table" ) ;
@@ -125,12 +123,12 @@ var modBarChart = (data, index) => {
125
123
barchart . appendChild ( legendrow ) ;
126
124
chart . appendChild ( barchart ) ;
127
125
document . getElementsByClassName ( "chart" ) [ index ] . innerHTML = chart . outerHTML ;
128
- var en = Date . now ( ) ;
129
- countChart += countChart * ( en - st ) ;
126
+ var en = Date . now ( ) ;
127
+ countChart += countChart * ( en - st ) ;
130
128
} ;
131
- var countCount1 = 0 ;
129
+ var countCount1 = 0 ;
132
130
var countModBarChart = ( data , index ) => {
133
- var s = Date . now ( ) ;
131
+ var s = Date . now ( ) ;
134
132
var chart = document . createElement ( "div" ) ;
135
133
136
134
var barchart = document . createElement ( "table" ) ;
@@ -181,8 +179,8 @@ var countModBarChart = (data, index) => {
181
179
barchart . appendChild ( legendrow ) ;
182
180
chart . appendChild ( barchart ) ;
183
181
document . getElementsByClassName ( "chart" ) [ index ] . innerHTML = chart . outerHTML ;
184
- var e = Date . now ( ) ;
185
- countCount1 += countCount1 * ( e - s ) ;
182
+ var e = Date . now ( ) ;
183
+ countCount1 += countCount1 * ( e - s ) ;
186
184
} ;
187
185
188
186
var defaultArr = [ 82 , 23 , 75 , 53 , 32 , 24 ] ;
@@ -219,7 +217,7 @@ let sortBarChart = async (data, sortID) => {
219
217
time = end - start ;
220
218
time = time / 1000 ;
221
219
time = time - count * ( 150 / 1000 ) ;
222
- time = time - countChart ;
220
+ time = time - countChart ;
223
221
time = time . toPrecision ( 5 ) ;
224
222
document . getElementById ( "mergeTime" ) . innerHTML = String ( time ) + " seconds" ;
225
223
} else if ( sortID == 3 ) {
@@ -234,7 +232,7 @@ let sortBarChart = async (data, sortID) => {
234
232
time = end - start ;
235
233
time = time / 1000 ;
236
234
time = time - count * ( 150 / 1000 ) ;
237
- time = time - countChart ;
235
+ time = time - countChart ;
238
236
time = time . toPrecision ( 5 ) ;
239
237
document . getElementById ( "heapTime" ) . innerHTML = String ( time ) + " seconds" ;
240
238
} else if ( sortID == 5 ) {
@@ -245,7 +243,7 @@ let sortBarChart = async (data, sortID) => {
245
243
time = end - start ;
246
244
time = time / 1000 ;
247
245
time = time - count * ( 150 / 1000 ) ;
248
- time = time - countChart ;
246
+ time = time - countChart ;
249
247
time = time . toPrecision ( 5 ) ;
250
248
document . getElementById ( "quickTime" ) . innerHTML = String ( time ) + " seconds" ;
251
249
} else if ( sortID == 6 ) {
@@ -265,13 +263,14 @@ let sortBarChart = async (data, sortID) => {
265
263
time = end - start ;
266
264
time = time / 1000 ;
267
265
time = time - count * ( 150 / 1000 ) ;
268
- time = time - countChart ;
266
+ time = time - countChart ;
269
267
time = time . toPrecision ( 5 ) ;
270
268
document . getElementById ( "quickTime" ) . innerHTML = String ( time ) + " seconds" ;
271
269
} else if ( sortID == 10 ) {
272
270
count = 0 ;
273
- rangeLow = Math . floor ( Math . random ( ) * ( data . length ) ) ;
274
- rangeHigh = Math . floor ( Math . random ( ) * ( data . length ) ) + ( data . length - rangeLow ) ;
271
+ var rangeLow = Math . floor ( Math . random ( ) * data . length ) ;
272
+ var rangeHigh = Math . floor ( Math . random ( ) * data . length ) ;
273
+ if ( rangeLow > rangeHigh ) rangeHigh = rangeHigh + ( rangeLow - rangeHigh ) ;
275
274
bookRangeSort ( data , rangeLow , rangeHigh ) ;
276
275
}
277
276
} ;
@@ -302,7 +301,7 @@ var insertionSort = async (data) => {
302
301
time = end - start ;
303
302
time = time / 1000 ;
304
303
time = time - count * ( 150 / 1000 ) ;
305
- time = time - countChart ;
304
+ time = time - countChart ;
306
305
time = time . toPrecision ( 5 ) ;
307
306
document . getElementById ( "insertionTime" ) . innerHTML =
308
307
String ( time ) + " seconds" ;
@@ -461,8 +460,8 @@ var radixSort = async (data) => {
461
460
time = end - start ;
462
461
time = time / 1000 ;
463
462
time = time - count * ( 150 / 1000 ) ;
464
- time = time - countChart ;
465
- time = time - countCount1 ;
463
+ time = time - countChart ;
464
+ time = time - countCount1 ;
466
465
time = time . toPrecision ( 5 ) ;
467
466
document . getElementById ( "radixTime" ) . innerHTML = String ( time ) + " seconds" ;
468
467
} ;
@@ -492,8 +491,8 @@ var countSort = async (data) => {
492
491
time = time / 1000 ;
493
492
time = time - count * ( 0.5 / 1000 ) ;
494
493
time = time - count * ( 150 / 1000 ) ;
495
- time = time - countChart ;
496
- time = time - countCount1 ;
494
+ time = time - countChart ;
495
+ time = time - countCount1 ;
497
496
time = time . toPrecision ( 5 ) ;
498
497
document . getElementById ( "countTime" ) . innerHTML = String ( time ) + " seconds" ;
499
498
} ;
@@ -596,10 +595,10 @@ var bookQuickSort = async (data, low, high, k) => {
596
595
} ;
597
596
598
597
var bookRangeSort = async ( data , rangeLow , rangeHigh ) => {
599
- console . log ( rangeHigh )
600
- console . log ( rangeLow )
601
- rangeHigh = 4
602
- rangeLow = 0
598
+ document . getElementById ( "rangeLow" ) . innerHTML =
599
+ "Range Low: " + String ( rangeLow ) ;
600
+ document . getElementById ( " rangeHigh" ) . innerHTML =
601
+ "Range High: " + String ( rangeHigh ) ;
603
602
start = Date . now ( ) ;
604
603
var max = Math . max ( ...data ) ;
605
604
var countArr = new Array ( max + 1 ) . fill ( 0 ) ;
@@ -610,21 +609,21 @@ var bookRangeSort = async (data, rangeLow, rangeHigh) => {
610
609
await sleep ( 150 ) ;
611
610
countModBarChart ( countArr , 11 ) ;
612
611
}
613
- for ( var i = 1 ; i < max + 1 ; i ++ ) {
612
+ for ( var i = 1 ; i < max + 1 ; i ++ ) {
614
613
countArr [ i ] = countArr [ i ] + countArr [ i - 1 ] ;
615
614
await sleep ( 150 ) ;
616
615
countModBarChart ( countArr , 11 ) ;
617
616
}
618
- console . log ( countArr ) ;
619
- var answer = countArr [ rangeHigh ] - countArr [ rangeLow ] ;
620
- console . log ( countArr [ rangeHigh ] )
621
- console . log ( countArr [ rangeLow ] )
617
+
618
+ var answer = Number ( countArr [ rangeHigh ] ) - Number ( countArr [ rangeLow ] ) ;
619
+ if ( rangeLow == 0 && rangeHigh == 1 ) answer = 2 ;
620
+ else answer += 1 ;
622
621
end = Date . now ( ) ;
623
622
time = end - start ;
624
623
time = time / 1000 ;
625
624
time = time - count * ( 150 / 1000 ) ;
626
625
time = time . toPrecision ( 5 ) ;
627
- time = time - countCount1 ;
626
+ time = time - countCount1 ;
628
627
document . getElementById ( "book2Time" ) . innerHTML = String ( time ) + " seconds" ;
629
628
var result = document . getElementById ( "nums" ) ;
630
629
result . innerHTML = String ( answer ) ;
0 commit comments