链表怎么遍历
郁闷的坦然 2014-01-10 07:36:14 type
PMyRec = ^MyRec;
MyRec = record
Name: string[8];
Age : Word;
Link: PMyRec;
end;
var
CurrentNode, FirstNode: PMyRec;
{建立链表}
procedure TForm1.FormCreate(Sender: TObject);
begin
New(FirstNode);
FirstNode.Name := '李四';
FirstNode.Age := 44;
FirstNode.Link := nil;
CurrentNode := FirstNode;
New(FirstNode);
FirstNode.Name := '张三';
FirstNode.Age := 33;
FirstNode.Link := CurrentNode;
CurrentNode := FirstNode;
New(FirstNode);
FirstNode.Name := '钱二';
FirstNode.Age := 22;
FirstNode.Link := CurrentNode;
CurrentNode := FirstNode;
New(FirstNode);
FirstNode.Name := '赵一';
FirstNode.Age := 11;
FirstNode.Link := CurrentNode;
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
Memo1.Lines.Add(CurrentNode.Name + #9 + IntToStr(CurrentNode.Age));
CurrentNode := CurrentNode.Link;
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;
链表怎么实现呀