program pengurutan berdasarkan Insertion Dengan C++

#include “stdio.h”

int main()
{
int L[20],temp,i,j,n=15;
printf(“pengurutan berdasarkan Insertion sort \nmasukkan %d elements: \n”,n);
for(i=0;i<n;i++){
scanf(“%d”,&L[i]);}

printf(“\nsebelum sorting: “);

for(i=0;i<n;i++){printf(“%d “,L[i]);}

for(i=1;i<n;i++){
temp=L[i];
j=i-1;
while((temp<L[j])&&(j>=0)){
L[j+1]=L[j];
j=j-1;
}
L[j+1]=temp;
}
printf(“\nsetelah sorting: “);
for(i=0;i<n;i++){printf(“%d “,L[i]);}
printf(“\n”);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s