hello, I hope so, that is what I mean ...
Could you explain it to me? I tried to compile it and tell me that goes for the loop
Code:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
void isort(int a[], int n){
int i;
int x=0;
int j=0;
for(i=1; i<n; i++){
x=a[i];
j=i;
while (j >0 && x< a[j-1]) {
a[j] = a[j-1];
j--;
}
a[j]= x;
}
}
int main(int argc, char** argv)
{
clock_t start, end, dif;
float tempo=0;
int N=0;
int M=0;
printf("Enter size of array: \n");
scanf("%d",&N);
printf("Now enter the range of elements: \n");
scanf("%d",&M);
int a[N];
printf("\n\n\t\t***ISORT***\n\n");
start=clock();
isort(a,N);
end=clock();
dif=end-start;
tempo=(float)dif/(float)CLOCKS_PER_SEC;
for (int i = 0; i < 100; ++i)
{
printf("completed %d\r", i);
fflush(stdout);
sleep(1);
}
return 0;
}
I put the source to run the insertion sort ...
In practice as well to measure the time I load a bar with a percentage ...
eg [======== ========] 50%
Bookmarks