排序的帮助.插入排序c#

本文关键字:插入排序 帮助 排序 | 更新日期: 2023-09-27 18:07:40

我有一个数组列表与一堆对象的所有相同的类(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)降序应用程序的大小(size)

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!");
    }

我尝试张贴列表的图片之前和之后,如果排序代码看起来很好,错误不与它。

排序的帮助.插入排序c#

就像你知道的那样,我把它修好了…

            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!");