標(biāo)題: 自創(chuàng)排序法 [打印本頁(yè)]

作者: liuda    時(shí)間: 2015-1-20 01:37
標(biāo)題: 自創(chuàng)排序法
覺(jué)得有缺點(diǎn)點(diǎn)請(qǐng)告訴我

C語(yǔ)言代碼:
        char  s[30],sd[11],i,j;若為了減少變量在RAM中占的空間在char后加xdata即可,但程序代碼段會(huì)增加字節(jié)
        char code a[]={17,2,6,12,23,2,3,4,21,9,5};//code是為了代碼空間占用少,不加會(huì)多次2百左右字節(jié),所以上面加了個(gè)存放數(shù)組
        for(i=0;i<sizeof(a);i++)
        {
                s[a]++;
        }
        //循環(huán)數(shù)組
        for(i=0;i<sizeof(s);i++)
        {
                //將排好的數(shù)覆蓋到原數(shù)組,當(dāng)有重復(fù)的下標(biāo)加1,數(shù)組對(duì)應(yīng)的值減1
                while(s)               
                {
                        sd[j]=i;
                        j++;
                        s--;
                }
        }
    Program Size: data=51.0 xdata=0 code=84
    代碼執(zhí)行總時(shí)間為393us。
    若char xdata s[30],sd[11],i,j;
    Program Size: data=9.0 xdata=43 code=169

C#代碼:
             string value="";
             int[] s = new int[30];            
            int i, j = 0;
            int[] a = { 17, 2, 6, 12, 23, 2, 3, 4, 21, 9, 5 };
            for (i = 0; i < 11; i++)
            {
                s[a]++;
            }
            //循環(huán)數(shù)組
            for (i = 0; i < 30; i++)
            {
                //將排好的數(shù)覆蓋到原數(shù)組,當(dāng)有重復(fù)的下標(biāo)加1,數(shù)組對(duì)應(yīng)的值減1
                while (s > 0)
                {
                    a[j] = i;//將原數(shù)組變?yōu)榕判蚝蟮膬?nèi)容
                    s+=i.ToString()+"  " ;
                    j++;
                    s--;
                }
            }
            MessageBox.Show(value) ;








歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1