#include <stdio.h>
void zhijiecharupaixu(int arr[],int length)
{
int temp = 0;
for(int i =0; i<length;++i)
{
temp = arr[i];
for (int j = i; j>0 && temp < arr[j - 1]; --j) //这一步确定前半部分数据有序
{
arr[j] = arr[j - 1];
}
arr[j] = temp;
}
}
void printfArr(int arr[],int length)
{
for(int i =0; i<length;++i)
{
//if(i%5 == 0)
// printf("\n");
printf("%d ",arr[i]);
}
}
int main()
{
int arry[] = {46 ,58, 15, 45, 90, 18, 10, 62} ;
int length = sizeof(arry)/4;
zhijiecharupaixu(arry,length);
printfArr(arry,length);
return 0;
}
void zhijiecharupaixu(int arr[],int length)
{
int temp = 0;
for(int i =0; i<length;++i)
{
temp = arr[i];
for (int j = i; j>0 && temp < arr[j - 1]; --j) //这一步确定前半部分数据有序
{
arr[j] = arr[j - 1];
}
arr[j] = temp;
}
}
void printfArr(int arr[],int length)
{
for(int i =0; i<length;++i)
{
//if(i%5 == 0)
// printf("\n");
printf("%d ",arr[i]);
}
}
int main()
{
int arry[] = {46 ,58, 15, 45, 90, 18, 10, 62} ;
int length = sizeof(arry)/4;
zhijiecharupaixu(arry,length);
printfArr(arry,length);
return 0;
}