我想通過字符的字符串,使併爲它分配,性格,一個鏈表分配字符串鏈表,宣佈像這樣:問題在阿達
type lstring is private;
type lstring_node;
type lstring_access is access lstring_node;
type lstring_node is
record
Char : character;
Position : integer;
Next : lstring_access;
end record;
private
type lstring is
record
First : lstring_access := null;
end record;
功能分配它是這樣的:
function toLstring (Input : string) return lstring is
LStr : lstring;
Current : lstring_access;
begin
-- Set the first item of LStr as Current.
-- LStr will from now on inherit the items of Current.
LStr.First := new lstring_node;
Current := LStr.First;
-- Iterate through the string and add it to the lstring.
for I in 1..Input'Length loop
if I /= 1 then
Current := new lstring_node;
end if;
Current.Char := Input(I);
Ada.Text_IO.Put(Current.Char);
Current.Position := I;
Current := Current.Next;
end loop;
-- Return the new lstring.
return LStr;
end toLstring;
我知道通過調試,for循環工作得很好,並且元素被分配給Current就好了。但由於某些原因這些項目沒有被添加到LStr。我需要在for循環之後聲明一些東西來完成它嗎?我的印象是,因爲Current被分配給LStr.First,LStr會繼承附加列表的其餘部分。我錯了嗎?
感謝
就像旁邊一樣,這是我遇到過的最令人震驚的自定義字符串類型。 – 2013-03-15 14:38:51