Insertion Sort
#include <stdio.h>
int main()
{
int arr[10] = {9,8,4,2,1,7,2,1,0,9};
int i;
int temp;
int j;
for(i = 1;i<10;i++)
{
temp = arr[i];
j = i-1;
while((temp< arr[j]) && (j>=0))
{
arr[j+1] = arr[j];
j = j-1;
}
arr[j+1] = temp;
}
for(i = 0;i<10;i++)
{
printf("%d",arr[i]);
}
}
Komentar
Posting Komentar