下列的排序算法是稳定的么?排序的结果是从大到小还是从小到大?任意排序方法如果给定O(n)的存储空间,则可以做到稳定,是否正确?
void Insertion_Sort_1(int a[],int n)
{
int i,j;
for(i = 1;i < n;i++)
{
int temp=a[i];
for(j = i;j > 0 && a[j-1] > temp; --j)
a[j] = a[j-1];
a[j]=temp;
}
}
void Insertion_Sort_2(int a[],int n)
{
int i,j;
for(i = 1;i < n;i++)
{
int temp=a[i];
for(j = i;j > 0 && a[j-1] >= temp; --j)
a[j] = a[j-1];
a[j]=temp;
}
}