#include "iostream"
void insertionsort(int data[],int n);
int main()
{
int number=9;
int data[]={5,6,4,8,2,3,7,9,1};
int i;
for (i=0;i<number;i++){
printf("%d",data[i]);
}
printf("\n");
insertionsort(data,number);
printf("\n");
for (i=0;i<number;i++){
printf("%d",data[i]);
}
printf("\n");
system("PAUSE");
return 0;
}
void insertionsort(int data[],int n){
int i,j;
for (i=1;i<n;i++){
int temp=data[i];
for (j=i;j>0;j--){
if (temp<data[j-1]){
data[j]=data[j-1];
data[j-1]=temp;
for (int k=0;k<n;k++){
printf("%d",data[k]);
}
printf("\n");
}
}
}
}
沒有留言:
張貼留言