0

我有一个 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!");
    }

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

4

1 回答 1

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!");
于 2013-04-11T17:28:58.980 回答