如何仅使用一个额外的整数变量对整数列表进行排序?

Igo*_*cic 2 c# java sorting puzzle algorithm

如何仅使用一个变量对值列表进行排序?

编辑:根据@ Igor的评论,我重新提出了这个问题.

Hug*_*len 6

C中的解决方案:

#include <stdio.h>

int main()
{
    int list[]={4,7,2,4,1,10,3};
    int n;  // the one int variable

    startsort:
    for (n=0; n< sizeof(list)/sizeof(int)-1; ++n)
        if (list[n] > list[n+1]) {
            list[n] ^= list[n+1];
            list[n+1] ^= list[n];
            list[n] ^= list[n+1];
            goto startsort;
        }

    for (n=0; n< sizeof(list)/sizeof(int); ++n)
        printf("%d\n",list[n]);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出当然与Icon程序相同.