it s other version of sorting program coded by C++
源代码在线查看: inser.c
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
void insertion_sort(int array[], int);
int main()
{
FILE *fp=fopen("input1.txt","r");//data.txt颇老阑 佬扁葛靛肺 悸泼
char data[20][3][5];//颇老俊辑 佬绢辑 历厘且函荐
int i=0,j=0;
char read_line[256];//颇老俊辑 茄临阑 佬绢辑 历厘且 函荐
char *str;//箭磊父 眠免且锭 荤侩且 函荐
int a[20][3];
while(1)
{
if(fscanf(fp,"%s",read_line)==EOF)break;//颇老俊辑 茄临阑 佬绢可聪促.
str=strtok(read_line,":");//"TAB:/"巩磊甫 哗绊 箭磊父 眠免钦聪促.
while(str != NULL)
{
strcpy(data[i][j],str);//眠免茄 箭磊甫 历厘 钦聪促.
str=strtok(NULL,": ");//澄巩磊甫 父朝锭 鳖瘤 眠免
j++;
}
j=0;
i++;
}
printf("籍瞒 切锅 己利\n");
//颇老俊辑 佬绢柯 单捞鸥甫 免仿
for(i=0;i < 20;i++)
{ for(j=0;j < 3;j++)
{
printf("%s ",data[i][j]);
}
printf("\n");
}
for(i=0;i < 20;i++)
{ for(j=0;j < 3;j++)
{
a[i][j]=atoi(data[i][j]);
}
}
printf("\n\nsort\n");
for(i=0;i < 20;i++)
{
for(j=0;j {
printf(" %d ",a[i][j]);
}
printf("\n");
}
insertion_sort(a[1],20);
for(i=0;i < 20;i++)
{
for(j=0;j {
printf(" %d ",a[i][j]);
}
printf("\n");
}
fclose(fp);
return 0;
}
void insertion_sort(int a[][], int n)
{
int i, j;
int temp;
for( i = 2; i {
temp = a[1][i - 1];
for( j = i - 2; i >= 0 && a[1][j] > temp; j--)
{
a[1][j + 1] = a[1][j];
}
a[1][j + 1] = temp;
}
}