[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]

[AIZU Online Judge] List of Top 3 Hills [c]

Problem Link: List of Top 3 Hills

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

[c]
#include<stdio.h>
void bubble_sort(int m[]);
int m[10],i,j,temp;
int main()
{
for(i=0;i<10;i++){
scanf("%d",&m[i]);
}
bubble_sort(m);
return 0;
}

void bubble_sort(int m[])
{
for(j=0;j<10-1;j++){
for(i=0;i<10-j-1;i++){
if(m[i]<m[i+1]){
temp=m[i+1];
m[i+1]=m[i];
m[i]=temp;
}
}
}
for(i=0;i<3;i++){
printf("%dn",m[i]);
}
}

[/c]