比如我现在有一个字符数组  mystr:=5,8,7,4,2    怎样把他从小到大排列成一个新的数组newstr(这个是数的数组,不是字符)??

解决方案 »

  1.   

    function maopao(a: array of integer): array;
    var i,j,temp:integer;
    begin
    for i := high(a) downto low(a) do
       begin
         for j := low(a) to i do
           begin
             if a[j]>a[j+1] then
               begin
                 temp := a[j];
                 a[j] := a[j+1];
                 a[j+1] := temp;
               end;
           end;
       end;
    end;
    我这样定义一个函数有问题吗?
    为什么说[DCC Error] Unit1.pas(55): E2029 Identifier expected but 'ARRAY' found
    我把array 改成tStringlist就可以了 
    但我想返回的类型是array
      

  2.   

    for i:=low(mystr) to high(mystr) do
    begin
    dosomething...
    end
      

  3.   

    以下是在同一个数组中进行排序的算法(快速排序算法)
    procedure intSort(pi: PIntegerArray; Count: Integer);  procedure QuickSort(L, R: Integer);
      var
        I, J, P: Integer;
        Tmp: Integer;
      begin
        repeat
          I := L;
          J := R;
          P := (L + R) shr 1;
          repeat
            while pi[I] < pi[P] do Inc(I);        while pi[J] > pi[P] do Dec(J);        if I <= J then
            begin
              //交换
              Tmp := pi[I];
              pi[I] := pi[J];
              pi[J] := Tmp;          if P = I then
                P := J
              else if P = J then
                P := I;
              Inc(I);
              Dec(J);
            end;
          until I > J;
          if L < J then QuickSort(L, J);
          L := I;
        until I >= R;
      end;begin
      QuickSort(0, Count - 1);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      a: array of Integer;
      i: Integer;
    begin
      //设置数组大小
      SetLength(a, 5);  //初始化
      a[0] := 5;
      a[1] := 8;
      a[2] := 7;
      a[3] := 4;
      a[4] := 2;  //排序
      intSort(@a[0], High(a) - Low(a) + 1);  Memo1.Lines.Clear;
      for i := 0 to High(a) do
        Memo1.Lines.Add(IntToStr(a[i]));
    end;
      

  4.   


    for i := high(a) downto low(a) do
    这里改成你的》?