[AIZU ONLINE JUDGE] ALDS1_1_A: Insertion Sort [c]

Problem Link: ALDS1_1_A: Insertion Sort

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A

[c]
#include<stdio.h>
int main()
{
int n,i,k;
scanf("%d",&n);
int arr[n];
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
for(k=0;k<n;k++){ if(k>0)
printf(" ");
printf("%d",arr[k]);
}
printf("n");
for(i=1;i<n;i++){ int temp,j; temp=arr[i]; j=i-1; while(j>=0 && arr[j]>temp){
arr[j+1]=arr[j];
j–;
}
j++;
arr[j]=temp;
for(k=0;k<n;k++){ if(k>0)
printf(" ");
printf("%d",arr[k]);
}
printf("n");
}
return 0;
}

[/c]

Advertisements

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 )

w

Connecting to %s