I am trying to see how many steps it will take to sort a set of ints via heap sort.
When I run it for a set of 100 numbers, I get z (# of operations) around 30,000 ( actualy: 29,534 or 30919 or 30903)Code:// x = how many random ints were generated int z = 0; for(int k=x;k>0;k–-){ for(int i=1;i<=k;i++){ item=A[i]; j=i/2; while(j>0 && A[j]<item){ A[i]=A[j]; i=j; j=j/2; } z++; // <------ **** A[i]=item; } temp=A[1]; A[1]=A[k]; A[k]=temp; }
if x = 500 I get around 3 million
Is this right?