Thema: Delphi Variablen sortieren

Einzelnen Beitrag anzeigen

the_source

Registriert seit: 16. Jun 2006
12 Beiträge
 
#15

Re: Variablen sortieren

  Alt 19. Jun 2006, 12:44
hmm, kann mir irgenwer erklären, warum der höchste Wert (wir hier provisorisch uf Label1 ausgeben) falsch ist?

Delphi-Quellcode:
procedure TForm1.StartClick(Sender: TObject);
 var
  s:String;
  counterMAIN:Integer;
  counterSET:Integer;
  counterCHAR:Integer;
  counterCOPY:Integer;
  counterSORT:Integer;
  countDEF:Integer;
  laenge:Integer;
  countArray: Array[65..90] of Integer;
  sortArray: Array[1..26] of Integer;
  unSort:boolean;
  tmp: Integer;
 begin
  for counterSET:= 1 to 26 do
   begin
    countArray[counterSET]:= 0;
   end;
  countDEF:= 0;
  s:= eingabe.Text;
  laenge:= Length(s);
  ProgressBar1.Max:= laenge;
  unSort:= true;
   for counterMAIN:= 1 to laenge do
    begin
     for counterCHAR:= 65 to 90 do
      begin
       if UpperCase(s[counterMAIN]) = CHR(counterCHAR) then
        begin
         countArray[counterCHAR]:= countArray[counterCHAR] + 1;
         countDEF:= countDEF + 1;
        end;
      end;
     ProgressBar1.Position:= ProgressBar1.Position + 1;
    end;
  for counterCOPY:= 1 to 26 do
   begin
    sortArray[counterCOPY]:= countArray[counterSORT + 64];
   end;
  while unSort = true do
   begin
    unSort:= false;
    for counterSORT:= 1 to 26 do
     begin
      if sortArray[counterSORT] < sortArray[counterSORT + 1] then
       begin
        tmp:= sortArray[counterSORT];
        sortArray[counterSORT]:= sortArray[counterSORT + 1];
        sortArray[counterSORT + 1]:= tmp;
        unSort:= true;
       end;
     end;
   end;
  OutA.Caption:= IntToStr(countArray[65]);
  OutB.Caption:= IntToStr(countArray[66]);
  OutC.Caption:= IntToStr(countArray[67]);
  OutD.Caption:= IntToStr(countArray[68]);
  OutE.Caption:= IntToStr(countArray[69]);
  OutF.Caption:= IntToStr(countArray[70]);
  OutG.Caption:= IntToStr(countArray[71]);
  OutH.Caption:= IntToStr(countArray[72]);
  OutI.Caption:= IntToStr(countArray[73]);
  OutJ.Caption:= IntToStr(countArray[74]);
  OutK.Caption:= IntToStr(countArray[75]);
  OutL.Caption:= IntToStr(countArray[76]);
  OutM.Caption:= IntToStr(countArray[77]);
  OutN.Caption:= IntToStr(countArray[78]);
  OutO.Caption:= IntToStr(countArray[79]);
  OutP.Caption:= IntToStr(countArray[80]);
  OutQ.Caption:= IntToStr(countArray[81]);
  OutR.Caption:= IntToStr(countArray[82]);
  OutS.Caption:= IntToStr(countArray[83]);
  OutT.Caption:= IntToStr(countArray[84]);
  OutU.Caption:= IntToStr(countArray[85]);
  OutV.Caption:= IntToStr(countArray[86]);
  OutW.Caption:= IntToStr(countArray[87]);
  OutX.Caption:= IntToStr(countArray[88]);
  OutY.Caption:= IntToStr(countArray[89]);
  OutZ.Caption:= IntToStr(countArray[90]);
  OutGES.Caption:= IntToStr(countDEF);
  Label1.Caption:= IntToStr(sortArray[1]);
 end;
  Mit Zitat antworten Zitat