#include <stdio.h>
#include <stdlib.h>
int insert_sort(int*, int, char*);
int main(int argc, char *argv[])
{
int i,size;
int A[10] = {7,3,4,1,8,9,0,5,2,6};
size = sizeof(A)/sizeof(int);
//insert_sort(A, size, "asc");
//insert_sort(A, size, "desc");
if (!insert_sort(A, size, "desc"))
{
for(i = 0; i < size; i++)
{
printf("A[%d] = %d\n", i, A[i]);
}
}
system("PAUSE");
return 0;
}
int insert_sort(int* data, int size, char* order)
{
int i,j,temp;
if (size <= 1)
return 0;
if ("asc" == order)
{
for(i = 1; i < size; i++)
{
for(j = i; j > 0; j--)
{
if (data[j] < data[j-1])
{
temp = data[j];
data[j] = data[j-1];
data[j-1] = temp;
}
}
}
}
else if ("desc" == order)
{
for(i = 1; i < size; i++)
{
for(j = i; j > 0; j--)
{
if (data[j] > data[j-1])
{
temp = data[j];
data[j] = data[j-1];
data[j-1] = temp;
}
}
}
}
else
return 1;
return 0;
}
る谿, 企殊姶手 if螳 れ願給. 一一襯 "<" ">"襦襷 覦蠑碁 襷伎. 譬 覦覯? 讒..