指針初始值該怎麼設定?(菜鳥求助)

icefirelxb 2003-08-18 09:16:40
關於下面的程序,我有兩個問題,第一:指針的初始值在這裡怎麼設置?我如何讓他指向鏈表的初始結點?第二,prior:=prior^.next;這條語句好象沒執行,為什麼?怎麼設置這個循環呢?

procedure TForm1.Button2Click(Sender: TObject);
//插入
type
PNode=^TNode;
TNode=Record
ElemValue:string;
prior:PNode;
next:PNode;
end;
var
prior:PNode;
begin
new(prior);
if prior^.ElemValue=Edit2.text then
begin
prior.next^.ElemValue :=Edit3.Text;

prior.next.next^.elemvalue:=prior.next^.ElemValue;
end;
prior:=prior^.next;
end;
...全文
46 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangxjn 2003-08-20
  • 打赏
  • 举报
回复
up
Jobs_Weng 2003-08-20
  • 打赏
  • 举报
回复
nil
icefirelxb 2003-08-19
  • 打赏
  • 举报
回复
我的鏈表定義是不是本身就有問題?
type
PNode=^TNode;
TNode=Record
ElemValue:string;
prior:PNode;
next:PNode;
head:pnode;
end;
var
head:PNode;
prior:PNode;
anext:PNode;
procedure TForm1.Button1Click(Sender: TObject);
//初始化
begin
new(prior);
new(anext);
prior.ElemValue:=S;
while(edit1.text<>'') do
begin
if prior.ElemValue='' then
begin
prior.ElemValue:=edit1.text;
Edit5.Text:= Edit5.Text+' '+prior^.ElemValue;
S:=edit1.Text;
S1:=edit1.Text;
head:=prior;
break;
end
else begin
anext.ElemValue:=edit1.text;
Edit5.Text:= Edit5.Text+' '+anext.ElemValue;
S:=edit1.Text;
S3:=edit1.Text;
end;
prior.next:=anext;
prior:=anext;
break;
end;
anext:=head;
end;
icefirelxb 2003-08-19
  • 打赏
  • 举报
回复
對不起,我開始考慮錯了.真正的問題是我在一個地方定義了一個鏈表,怎麼在插入函數裡把它都出來並進行插入操作?
robbot 2003-08-18
  • 打赏
  • 举报
回复
prior.next.next^.elemvalue:=prior.next^.ElemValue;有问题
prior.next^.next^.elemvalue:=prior.next^.ElemValue;
你到底想干嘛??
lxpbuaa 2003-08-18
  • 打赏
  • 举报
回复
例子:
procedure TForm1.Button1Click(Sender: TObject);
type
PNode=^TNode;
TNode=Record
ElemValue:string;
prior:PNode;
next:PNode;
end;
var
Nodes: Array of PNode;
I: Integer;
P: PNode;
begin
SetLength(Nodes, 5);
for I := Low(Nodes) to High(Nodes) do
begin
New(Nodes[I]);
with Nodes[I]^ do
begin
ElemValue := IntToStr(I);
prior := nil;
next := nil;
end;
if I > Low(Nodes) then
begin
Nodes[I].prior := Nodes[I-1];
Nodes[I-1].next := Nodes[I];
end;
end;
P := Nodes[0];
while P.next <> nil do
begin
ShowMessage(P.ElemValue);
P := P.next;
end;
//最后用Dispose释放所有链表的节点
end;

—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧