排序帮助。插入排序c#

时间:2013-04-05 11:31:52

标签: c# sorting inheritance polymorphism insertion-sort

我有一个Arraylist,其中有一堆对象都是同一个类(DistributedApps)。

构造函数:

public Distributedapps(string appName, string devName, string description, double size, int estLife,double price, int downloads,int ratings,string distributor, double annLicenceFee, int maxUsers)
            :base(appName,devName,description,size,estLife,price,downloads,ratings)

我希望Insertionsort按照应用程序大小(大小)降序排列此列表(DeployedApps)

public void DeployInsertionSortAppSizeDeployed()
    {
        Console.WriteLine("INSERTION SORT ON APP SIZE DEPLOYED!");
        int II;
        Distributedapps Temp, PrTemp;
        for (int IO = 1; IO <= (Count(DeployedApps) - 1); IO++)
        {
            Temp = (Distributedapps)DeployedApps[IO];
            II = IO;
            PrTemp = (Distributedapps)DeployedApps[II - 1];
            while ((II > 0) && (PrTemp.GetSize().CompareTo(Temp.GetSize()) <= 0)) 
            {
                DeployedApps[II] = DeployedApps[II - 1];
                II -=1;
            }
            DeployedApps[II] = Temp;
        }
        Console.WriteLine("DONE!");
    }

如果排序代码看起来很好并且错误不适合,我会尝试在列表之前和之后发布列表图片。

1 个答案:

答案 0 :(得分:0)

就这样你知道互联网我修好了......

            Console.WriteLine("INSERTION SORT ON APP SIZE DEPLOYED!");
        Apps Temp, PrTemp;
        int II;
        for (int IO = 1; IO <= (Count(DeployedApps) - 1); IO++)
        {
            Temp = (Apps)DeployedApps[IO];
            PrTemp = (Apps)DeployedApps[IO - 1];
            II = IO;
            while ((II>0)&&(Temp.GetSize()>=PrTemp.GetSize()))
            {
                SwapDEP(II, II - 1);
                II = II - 1;
                if (II >= 1)
                {
                    Temp = (Apps)DeployedApps[II];
                    PrTemp = (Apps)DeployedApps[II - 1];
                }
            }

        }
        Console.WriteLine("DONE!");