Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Алгоритм Грэхема / Source / LIST
.PAS unit list;
interface
type
vertex=record
x,y,number:integer;
end;
type
plvertex=^lvertex;
lvertex=record
used:integer;
x,y,number:integer;
next,previos: plvertex;
end;
type
TListVertex=class
public
beginList,current : plvertex;
procedure AddVector(x,y,num:integer);
procedure DeleteVector(V:plVertex);
constructor Create;
procedure Free;
end;
implementation
procedure TListVertex.AddVector(x,y,num:integer);
var T,C:plvertex;
begin
new (T);
T^.x:=x; T^.y:=y; T^.number:=num;
if (beginList=nil) then
begin
beginList:=T; current:=T;
T^.previos:=beginList; T^.next:=beginList;
T^.x:=x; T^.y:=y; T^.number:=num; T^.used:=0;
end
else
begin
C:=beginList;
while (C^.next<>beginList) do C:=C^.next;
C^.next:=T; T^.previos:=C;T^.next:=beginList;
beginList.previos:=T;T^.used:=0;
end;
end;
procedure TListVertex.DeleteVector(V:plVertex);
var p,n:plVertex;
begin
p:=V.previos; n:=V.next;
p^.next:=n; n^.previos:=p;
dispose(V);
end;
constructor TListVertex.Create;
begin
beginList:=nil;
current:=nil;
end;
procedure TListVertex.Free;
var t,b:plvertex;
begin
if (beginList<>nil) then
begin
current:=beginList;
t:=current; current:=current^.next;
dispose(t);
while (current<>beginList) do
begin
t:=current; current:=current^.next;
dispose(t);
end;
current:=nil; beginList:=nil;
end;
end;
end.
interface
type
vertex=record
x,y,number:integer;
end;
type
plvertex=^lvertex;
lvertex=record
used:integer;
x,y,number:integer;
next,previos: plvertex;
end;
type
TListVertex=class
public
beginList,current : plvertex;
procedure AddVector(x,y,num:integer);
procedure DeleteVector(V:plVertex);
constructor Create;
procedure Free;
end;
implementation
procedure TListVertex.AddVector(x,y,num:integer);
var T,C:plvertex;
begin
new (T);
T^.x:=x; T^.y:=y; T^.number:=num;
if (beginList=nil) then
begin
beginList:=T; current:=T;
T^.previos:=beginList; T^.next:=beginList;
T^.x:=x; T^.y:=y; T^.number:=num; T^.used:=0;
end
else
begin
C:=beginList;
while (C^.next<>beginList) do C:=C^.next;
C^.next:=T; T^.previos:=C;T^.next:=beginList;
beginList.previos:=T;T^.used:=0;
end;
end;
procedure TListVertex.DeleteVector(V:plVertex);
var p,n:plVertex;
begin
p:=V.previos; n:=V.next;
p^.next:=n; n^.previos:=p;
dispose(V);
end;
constructor TListVertex.Create;
begin
beginList:=nil;
current:=nil;
end;
procedure TListVertex.Free;
var t,b:plvertex;
begin
if (beginList<>nil) then
begin
current:=beginList;
t:=current; current:=current^.next;
dispose(t);
while (current<>beginList) do
begin
t:=current; current:=current^.next;
dispose(t);
end;
current:=nil; beginList:=nil;
end;
end;
end.
Соседние файлы в папке Source