**Unformatted text preview: **for (i=last/2; i>0; i--) maxshift(a, i, last); for (i=1; i<a.length; i++) { int x=a[last-1]; a[last-1]=a[0]; a[0]=x; last--; maxshift(a, 1, last); } } public static void maxshift(int a, int i, int last) { int j=2*i; int x=a[i-1]; if ((j<last)&&(a[j]>a[j-1])) j++; while((j<=last)&&(a[j-1]>x)) { a[i-1]=a[j-1]; i=j; j=2*j; if ((j<last)&&(a[j]>a[j-1])) j++; } a[i-1]=x; } }...

View
Full Document

- Fall '16
- James Korsh
- Sort, Harshad number, int x=a, int last=a.length