File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
algorithm/sorting/quick/basic Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 11tracer . _print ( 'original array = [' + D . join ( ', ' ) + ']' ) ;
22tracer . _sleep ( 1000 ) ;
33tracer . _pace ( 500 ) ;
4+
45function quicksort ( low , high ) {
56 if ( low < high ) {
67 var p = partition ( low , high ) ;
78 quicksort ( low , p - 1 ) ;
89 quicksort ( p + 1 , high ) ;
910 }
1011}
12+
1113function partition ( low , high ) {
1214 var pivot = D [ high ] ;
1315 tracer . _selectSet ( [ low , high ] ) ;
1416 var i = low ;
17+ var temp ;
18+
1519 for ( var j = low ; j < high ; j ++ ) {
1620 if ( D [ j ] <= pivot ) {
17- var temp = D [ i ] ;
21+ temp = D [ i ] ;
1822 D [ i ] = D [ j ] ;
1923 D [ j ] = temp ;
2024 tracer . _notify ( i , j ) ;
2125 i ++ ;
2226 }
2327 }
24- var temp = D [ i ] ;
28+ temp = D [ i ] ;
2529 D [ i ] = D [ high ] ;
2630 D [ high ] = temp ;
2731 tracer . _notify ( i , high ) ;
2832 tracer . _deselectSet ( [ low , high ] ) ;
2933 return i ;
3034}
35+
3136quicksort ( 0 , D . length - 1 ) ;
32- tracer . _print ( 'sorted array = [' + D . join ( ', ' ) + ']' ) ;
37+ tracer . _print ( 'sorted array = [' + D . join ( ', ' ) + ']' ) ;
You can’t perform that action at this time.
0 commit comments