File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
program/c/src/oracle/model Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -14,27 +14,29 @@ void heapsort(int64_t * a, uint64_t n) {
1414 /*
1515 * This is a bottom-up heapify which is linear in time.
1616 */
17- for (int i = n / 2 - 1 ; i >= 0 ; i -- ) {
17+ for (uint64_t i = n / 2 - 1 ;; -- i ) {
1818 int64_t root = a [i ];
19- int j = i * 2 + 1 ;
19+ uint64_t j = i * 2 + 1 ;
2020 while (j < n ) {
21- if (j + 1 < n && a [j ] < a [j + 1 ]) j ++ ;
21+ if (j + 1 < n && a [j ] < a [j + 1 ]) ++ j ;
2222 if (root >= a [j ]) break ;
2323 a [(j - 1 ) / 2 ] = a [j ];
2424 j = j * 2 + 1 ;
2525 }
2626 a [(j - 1 ) / 2 ] = root ;
27+
28+ if (i == 0 ) break ;
2729 }
2830
29- for (int i = n - 1 ; i > 0 ; i -- ) {
31+ for (uint64_t i = n - 1 ; i > 0 ; -- i ) {
3032 int64_t tmp = a [0 ];
3133 a [0 ] = a [i ];
3234 a [i ] = tmp ;
3335
3436 int64_t root = a [0 ];
35- int j = 1 ;
37+ uint64_t j = 1 ;
3638 while (j < i ) {
37- if (j + 1 < i && a [j ] < a [j + 1 ]) j ++ ;
39+ if (j + 1 < i && a [j ] < a [j + 1 ]) ++ j ;
3840 if (root >= a [j ]) break ;
3941 a [(j - 1 ) / 2 ] = a [j ];
4042 j = j * 2 + 1 ;
You can’t perform that action at this time.
0 commit comments