我声明的链表如下:
type
PImageInfor=^TImageInfor;
TImageInfor=record
filename:string;
fileid:integer;
next:PImageInfor;
Prior:PImageInfor;
end;然后定义了几个全局变量:
head,last,p:PImageInfor;在Form.Create事件中初始化全局变量:
new(head);
head.next:=nil;
head.prior:=nil;
last:=head;在button1中建立链表,在button2中遍历链表
button1的事件如下:
for i:=0 to 10 do
begin
new(p);
p.fileid:=i;
p.next:=nil;
p.Prior:=last;
last.next:=p;
last:=last.next;
dispose(p);
end;在button2中遍历:
p:=head.next;
while(p<>nil)do
begin
listbox1.items.add(inttostr(p.fileid));
p:=p.next;
end;按道理,在listbox中显示的应该是0~10这几个数。但是我得到的结果是6~10这几个数。
而且如果我在button2的遍历事件中,在p:=head.next后加一句:showmessage(inttostr(p.fileid)),在listbox中得到的数就只有一个0了。我已经要晕死了,乱七八糟的链表
type
PImageInfor=^TImageInfor;
TImageInfor=record
filename:string;
fileid:integer;
next:PImageInfor;
Prior:PImageInfor;
end;然后定义了几个全局变量:
head,last,p:PImageInfor;在Form.Create事件中初始化全局变量:
new(head);
head.next:=nil;
head.prior:=nil;
last:=head;在button1中建立链表,在button2中遍历链表
button1的事件如下:
for i:=0 to 10 do
begin
new(p);
p.fileid:=i;
p.next:=nil;
p.Prior:=last;
last.next:=p;
last:=last.next;
dispose(p);
end;在button2中遍历:
p:=head.next;
while(p<>nil)do
begin
listbox1.items.add(inttostr(p.fileid));
p:=p.next;
end;按道理,在listbox中显示的应该是0~10这几个数。但是我得到的结果是6~10这几个数。
而且如果我在button2的遍历事件中,在p:=head.next后加一句:showmessage(inttostr(p.fileid)),在listbox中得到的数就只有一个0了。我已经要晕死了,乱七八糟的链表
解决方案 »
- AdvStringGrid 单元格合并之后数据为什么只是横向居中呢?
- 我只会用ADOquery,不会用Dataset,有没有Dataset的教程啊!
- 今天搜索不了,请教高手:TCP HTTP UDP socks 概念 关系和区别!
- 查找日期为空的记录该怎么办
- 我用的时多线程,为什么主程序窗还会出现无响应情况???
- 就要毕业了,好久不来了!不知道工作是否要找软件开发?
- 关于oracle的问题
- 在日期函数中有没有可以只加月的呢?(举个例子更好)
- 谁能告诉我怎样在Delphi4.0中使用CrystalReport,最好是8.0
- 请问如何得到系统目录?如98的windows/system 或NT 的winnt/system32
- 如何从SELECT a,b FROM TABLE1 COMPUTE SUM(a)产生的两个结果集中取出SUM(a)
- 寻求BDE转化为DBEXPRESS的最佳方案
begin
new(p);
p.fileid:=i;
p.next:=nil;
p.Prior:=last;
last.next:=p;
last:=last.next;
dispose(p);
end;好像有问题,不应该dispose(p)的,你试试。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons;type
PImageInfor=^TImageInfor;
TImageInfor=record
filename:string;
fileid:integer;
next:PImageInfor;
Prior:PImageInfor;
end;
TForm1 = class(TForm)
Button1: TButton;
Shape1: TShape;
BitBtn1: TBitBtn;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
head,last:PImageInfor; public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
p: PImageInfor;
begin
for i:=0 to 10 do
begin
new(p);
p.fileid:=i;
p.next:=nil;
p.Prior:=last;
last.next:=p;
last:=last.next;
end;end;procedure TForm1.FormCreate(Sender: TObject);
begin
new(head);
head.next:=nil;
head.prior:=nil;
last:=head;end;procedure TForm1.BitBtn1Click(Sender: TObject);
var p: PImageInfor;
begin
p:=head.next;
while(p <> nil)do
begin
listbox1.items.add(inttostr(p.fileid));
p:=p.next;
end;end;end.========================================================================
如果可以请支持一下
http://expert.csdn.net/Expert/topic/2308/2308724.xml?temp=.2405664