最簡單的冒泡法,要是字串,可以使用Tstringlist:
procedure TForm1.Button4Click(Sender: TObject);
var
aa: Array [0 .. 3] Of integer;
i: integer;
begin
aa[0] := 30;
aa[1] := 33;
aa[2] := 503;
aa[3] := 21;
Sort(aa);
for i := 0 to high(aa) do
Memo1.Lines.Add(inttostr(aa[i]));
end;
procedure TForm1.Sort(var x: array of integer);
var
i, j, l: integer;
begin
for i := 0 to high(x) do
begin
for j := 0 to high(x) - 1 do
begin
if x[j] > x[j + 1] then
begin
l := x[j];
x[j] := x[j + 1];
x[j + 1] := l;
end;
end;
end;
end;
procedure Sort(const A: array of PInteger);
var
N: array of integer;
i: integer;
begin
SetLength(N, Length(A));
for i := Low(A) to High(A) do
N[i] := A[i]^;
TArray.Sort<integer>(N);
for i := Low(A) to High(A) do
A[i]^ := N[i];
end;
procedure Sort(const A: array of PInteger);
var
N: array of integer;
i: integer;
begin
SetLength(N, Length(A));
for i := Low(A) to High(A) do
N[i] := A[i]^;
TArray.Sort<integer>(N);
for i := Low(A) to High(A) do
A[i]^ := N[i];
end;
procedure Sort(const A: array of PInteger);
var
N: array of integer;
i: integer;
procedure __Sort(var x: array of integer);
var
i, j, l: integer;
begin
for i := 0 to high(x) do
begin
for j := 0 to high(x) - 1 do
begin
if x[j] > x[j + 1] then
begin
l := x[j];
x[j] := x[j + 1];
x[j + 1] := l;
end;
end;
end;
end;
begin
SetLength(N, Length(A));
for i := Low(A) to High(A) do
N[i] := A[i]^;
//TArray.Sort<integer>(N);
__Sort(N);
for i := Low(A) to High(A) do
A[i]^ := N[i];
end;
uj5u.com熱心網友回復:
就用我的代碼加上秋天之落葉的代碼就可以了:
procedure Sort(const A: array of PInteger);
var
N: array of integer;
i: integer;
procedure __Sort(var x: array of integer);
var
i, j, l: integer;
begin
for i := 0 to high(x) do
begin
for j := 0 to high(x) - 1 do
begin
if x[j] > x[j + 1] then
begin
l := x[j];
x[j] := x[j + 1];
x[j + 1] := l;
end;
end;
end;
end;
begin
SetLength(N, Length(A));
for i := Low(A) to High(A) do
N[i] := A[i]^;
//TArray.Sort<integer>(N);
__Sort(N);
for i := Low(A) to High(A) do
A[i]^ := N[i];
end;
一個是執行出值排序的 一個代碼執行不出來
uj5u.com熱心網友回復:
就用#15那個sort,原樣復制,不要改。
uj5u.com熱心網友回復:
就用#15那個sort,原樣復制,不要改。
__Sort(a);
for j := 0 to high(a) do
Memo1.Lines.Add(inttostr(a[j])); 程序可以執行 這個執行不了
uj5u.com熱心網友回復:
用這個procedure Sort(const A: array of PInteger);
的Sort
不要用__Sort,后者是內部嵌套程序
uj5u.com熱心網友回復:
用這個procedure Sort(const A: array of PInteger);
的Sort
不要用__Sort,后者是內部嵌套程序
一樣的 是變數的定義有問題嗎 ?
a: Array [0.. 9] of integer; 是這樣定義的
uj5u.com熱心網友回復:
用這個procedure Sort(const A: array of PInteger);
的Sort
不要用__Sort,后者是內部嵌套程序
Sort(aa);
for i := 0 to high(aa) do
begin
if aa[i] = a0 then
Memo1.Lines.Add('a0='+inttostr(aa[i]));
if aa[i] = a1 then
Memo1.Lines.Add('a1='+inttostr(aa[i]));
if aa[i] = a2 then
Memo1.Lines.Add('a2='+inttostr(aa[i]));
if aa[i] = a3 then
Memo1.Lines.Add('a3='+inttostr(aa[i]));
end;
end;
procedure TForm12.Sort(var x: array of integer);
var
i, j, l: integer;
begin
for i := 0 to high(x) do
begin
for j := 0 to high(x) - 1 do
begin
if x[j] > x[j + 1] then
begin
l := x[j];
x[j] := x[j + 1];
x[j + 1] := l;
end;
end;
end;
end;
Sort(aa);
for i := 0 to high(aa) do
begin
if aa[i] = a0 then
Memo1.Lines.Add('a0='+inttostr(aa[i]));
if aa[i] = a1 then
Memo1.Lines.Add('a1='+inttostr(aa[i]));
if aa[i] = a2 then
Memo1.Lines.Add('a2='+inttostr(aa[i]));
if aa[i] = a3 then
Memo1.Lines.Add('a3='+inttostr(aa[i]));
end;
end;
procedure TForm12.Sort(var x: array of integer);
var
i, j, l: integer;
begin
for i := 0 to high(x) do
begin
for j := 0 to high(x) - 1 do
begin
if x[j] > x[j + 1] then
begin
l := x[j];
x[j] := x[j + 1];
x[j + 1] := l;
end;
end;
end;
end;
var a: Array [0.. 9] of integer;
i,j:integer;
begin
for i:=1 to 10-1 do
for j:=2 to 10 do
if A[j]<A[j] then
begin
k:=A[i];
A[i]:=B[j];
B[j]:=k;
end;
作一個排序即可。
end;
uj5u.com熱心網友回復:
用這個procedure Sort(const A: array of PInteger);
的Sort
不要用__Sort,后者是內部嵌套程序
把Sort提到前面去。
uj5u.com熱心網友回復:
陣列回圈的復原,我試了還幾個方法,都不能成功,樓上的大神們的也沒有運行成功,自己確實太笨,只好想別的辦法了,辦法很笨,用著還行,大家別笑就行,哈哈哈:
procedure TForm16.Button2Click(Sender: TObject);
var
t1, t2, t0, new: string;
i: integer;
begin
t1 := '21,54,201,54,21,78,21,142';
t2 := 'AA,BB,CC,DD,EE,FF,GG,HH';
for i := 0 to 7 do
begin
t0 := GetManValue(t1, t2);
Memo1.Lines.add(t0);
new := '-' + (i + 1).ToString;
t1 := StringReplace(t1, copy(t0, 4, Length(t0) - 3), new, [rfIgnoreCase]);
end;
end;
function TForm16.GetManValue(s1, s2: string): string;
var
ss1, ss2: TStringList;
ManIndex: integer;
i: integer;
begin
ss1 := TStringList.Create;
ss2 := TStringList.Create;
ss1.Delimiter := ',';
ss1.DelimitedText := s1;
ss2.Delimiter := ',';
ss2.DelimitedText := s2;
ManIndex := 0;
for i := 1 to ss1.Count - 1 do
begin
if StrToInt(ss1[i]) > StrToInt(ss1[ManIndex]) then
ManIndex := i;
end;
result := ss2[ManIndex] + '=' + ss1[ManIndex];
ss1.Free;
ss2.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a1,a2,a3,a4,a5:Integer;
aa:array [0..4] of Pint;
i,j:Integer;
procedure BubbleSort(b:array of Pint);
var
i,j,p:Integer;
t:Pint;
a:array of Integer;
begin
SetLength(a,Length(b));
for i:=Low(B) to High(B) do
a[i]:=b[i]^;
for i:=Low(A) to High(A)-1 do
for j:=i+1 to High(A) do
if a[i]>a[j] then
begin
p:=a[i];
a[i]:=a[j];
a[j]:=p;
end;
for i:=Low(B) to High(B) do
b[i]^:=a[i];
Sort(aa);
for i := 0 to high(aa) do
begin
if aa[i] = a0 then
Memo1.Lines.Add('a0='+inttostr(aa[i]));
if aa[i] = a1 then
Memo1.Lines.Add('a1='+inttostr(aa[i]));
if aa[i] = a2 then
Memo1.Lines.Add('a2='+inttostr(aa[i]));
if aa[i] = a3 then
Memo1.Lines.Add('a3='+inttostr(aa[i]));
end;
end;
procedure TForm12.Sort(var x: array of integer);
var
i, j, l: integer;
begin
for i := 0 to high(x) do
begin
for j := 0 to high(x) - 1 do
begin
if x[j] > x[j + 1] then
begin
l := x[j];
x[j] := x[j + 1];
x[j + 1] := l;
end;
end;
end;
end;
眾所周知,C ++的學習曲線陡峭,但是花時間學習這種語言將為您的職業帶來奇跡,并使您與其他開發人員區分開。您會更輕松地學習新語言,形成真正的解決問題的技能,并在編程的基礎上打下堅實的基礎。 C ++將幫助您養成良好的編程習慣(即清晰一致的編碼風格,在撰寫代碼時注釋代碼,并限制類內部的可見性),并且由 ......
值傳遞不會改變本身,參考傳遞(如果傳遞的值需要實體化到堆里)如果發生修改了會改變本身。 1.基本資料型別都是值傳遞 package com.example.basic; public class Test { public static void main(String[] args) { int ......