2013-04-05 148 views
0

我有一堆對象都是同一類(DistributedApps)的Arraylist。排序幫助。插入排序c#

構造:

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) 

我想插入排序排序此列表(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!"); 
    } 

我嘗試列表的發佈照片之前,如果排序後代碼看起來很好,並沒有與它的錯誤。

+0

那麼,有什麼問題嗎?你的分揀機不工作?它是否會拋出任何異常?它不會編譯? – Nolonar 2013-04-05 11:36:05

+0

它確實排序正確。列表頂部的前兩個對象被錯誤地排序。列表的其餘部分正確排序。 – 2013-04-05 11:40:32

+0

'應用程序大小(大小)'是「DistributedApps」類的一個字段? – Maris 2013-04-05 11:51:46

回答

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