请各位大侠帮帮小弟吧! 急!急!急! (50分)

  • 主题发起人 主题发起人 qdxxahui
  • 开始时间 开始时间
Q

qdxxahui

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟我现在要写一个线性表的类,它主要包含如下几个函数:1。定义这个线性表的长度;
2。判断这个线性表是否为空;3。在线性表中插入一个元素;4。在线性表中删除一个元素;5。初始化此线性表。(与Tlist很像)
请一定要把完成的代码给小弟拜读一下。
 
给你一个类似的代码吧,我自己做的。你拿去改一改吧。
TFeatures = class //符号属性集类
private
FCount :SmallInt;
FFeatures :array of TFeature;
function GetCount :SmallInt;
function GetFeature(Index: Integer) :TFeature;
public
procedure Add(Feature: TFeature);
procedure Remove(Index: Integer);
procedure RemoveAll;
constructor Create; overload;
destructor Destroy; override;
property Items[Index: Integer] :TFeature read GetFeature;
published
property Count :SmallInt read GetCount;
end;
constructor TFeatures.Create;
begin
FCount:=0;
SetLength(FFeatures, FCount);
end;
destructor TFeatures.Destroy;
var
i:integer;
begin
for i:=0 to Length(FFeatures)-1 do FFeatures.Free;
inherited;
end;
procedure TFeatures.Add(Feature: TFeature);
begin
FCount:=Length(FFeatures);
SetLength(FFeatures, FCount+1);
FFeatures[FCount]:=Feature;
FCount:=FCount+1;
end;
procedure TFeatures.Remove(Index: Integer);
var
i : integer;
begin
if Index>FCount-1 then Application.MessageBox('此索引大于最大值!', '提示', 0)
else begin
for i:=Index to FCount-2 do FFeatures:=FFeatures[i+1];
FFeatures[FCount-1].Free;
FCount:=FCount-1;
SetLength(FFeatures, FCount);
end;
end;
procedure TFeatures.RemoveAll;
var
i:integer;
begin
for i:=0 to Length(FFeatures)-1 do FFeatures.Free;
FCount:=0;
SetLength(FFeatures, FCount);
end;
function TFeatures.GetFeature(Index: Integer): TFeature;
begin
Result:=nil;
if Index>FCount-1 then Application.MessageBox('此索引大于最大值!', '提示', 0)
else begin
Result:=FFeatures[Index];
end;
end;
function TFeatures.GetCount :SmallInt;
begin
FCount:=Length(FFeatures);
Result:=FCount;
end;
 
接受答案了.
 
后退
顶部