• 主页

##### 链表怎么遍历
type
PMyRec = ^MyRec;
MyRec = record
Name: string[8];
Age : Word;
end;

var
CurrentNode, FirstNode: PMyRec;

{建立链表}
procedure TForm1.FormCreate(Sender: TObject);
begin
New(FirstNode);
FirstNode.Name := '李四';
FirstNode.Age := 44;
CurrentNode := FirstNode;

New(FirstNode);
FirstNode.Name := '张三';
FirstNode.Age := 33;
CurrentNode := FirstNode;

New(FirstNode);
FirstNode.Name := '钱二';
FirstNode.Age := 22;
CurrentNode := FirstNode;

New(FirstNode);
FirstNode.Name := '赵一';
FirstNode.Age := 11;
CurrentNode := FirstNode;

Button1.Caption := '遍历链表';
Button2.Caption := '插入节点';
Button3.Caption := '删除节点';
Button4.Caption := '删除链表';

Memo1.Align := alLeft;
Memo1.ScrollBars := ssVertical;
end;

//这个只能有一个循环
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Clear;
CurrentNode := FirstNode;
while Assigned(CurrentNode) do
begin
end;
end;

FOR I:=0 TO tstringlist.count -1 DO BEGIN
x:=i+1 to tstringlist.count -1do begin
if stringlist.strings[i]=stringlist.strings[x] then begin
//我在这里有操作，需要拿I的数据和X的数据做比较，类似冒泡排序
end;
end;
END;

...全文
116 点赞 收藏 4

4 条回复

3418

3.3w+

Delphi 语言基础/算法/系统设计