顺序排序这样写程序为什么会错误呢/
这是我写的一个对整数数组按从小到大的顺序排序的程序,请大家帮我看看哪里写错了,谢谢了;
程序代码:/**************************************************************************************************************
*file:paixu.c
*
*function:顺序排序程序
*
***************************************************************************************************************/
#include<stdio.h>
#define max 1000 //定义最大数组长度1000;
#define sign 123//定义终止输入标识符:数字123;
static int findsmallindex(int array[max],int i,int n);//寻找最小整数下标函数声明;
static void swapinteger (int array[max],int i,int smallindex);//交换数组元素函数声明;
void main()
{
int array[max],n=0,value,smallindex,i;
printf("this program sort the first n elements in array into increasing numberical order");
printf("the length of the array must less than 1000\n");
printf("please input the data and use the integer 123 as terminate sign\n");
while(1)//用户输入数据存入数组array[max]循环;
{
scanf("%d",&array[n]);
value=array[n];
if(value==sign)
{
printf("terminate sign is occur\n");
break;
}
if(n>=1000)
{
printf("the input is too many\n");
break;
}
n++;
}
for(i=0;i<n-1;i++)//排序循环;
{
smallindex=findsmallinteger(array[max],i,n-1);//寻找i到n的最小整数下标smallinteger函数;
swapinteger(array[max],i,smallindex);//交换array[i]和array[smallindex]函数;
}
for(i=0;i<=n-1;i++)//输出循环;
{
printf("%d\t",array[i]);
}
printf("\n");
}
//子函数1:寻找最小整数的下标函数;
static int findsmallinteger(int array[max],int i,int n)
{
int j,smallest=array[i],k=i;
for(j=i+1;j<=n;j++)
{
if(array[j]<smallest)
{
smallest=array[j];
k=j;
}
}
return (k);
}
//子函数2:交换数组元素函数;
static void swapinteger (int array[max],int i,int smallindex)
{
int temp;
temp=array[i];
array[i]=array[smallindex];
array[smallindex]=temp;
}




