81 lines
1.4 KiB
ObjectPascal
81 lines
1.4 KiB
ObjectPascal
|
|
unit cell_m;
|
||
|
|
|
||
|
|
interface
|
||
|
|
|
||
|
|
type
|
||
|
|
cellItemPtr = ^cellItem;
|
||
|
|
|
||
|
|
cellItem = record
|
||
|
|
x, y: integer;
|
||
|
|
next: cellItemPtr
|
||
|
|
end;
|
||
|
|
|
||
|
|
QCell = record
|
||
|
|
first, last: cellItemPtr
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure InitCell(var c: cellItem; x, y: integer);
|
||
|
|
procedure QCellInit(var q: QCell);
|
||
|
|
procedure QCellPush(var q: QCell; var c: cellItem);
|
||
|
|
function QCellIsEmpty(var q: QCell): boolean;
|
||
|
|
function QCellGet(var q: QCell): cellItemPtr;
|
||
|
|
procedure QCellPop(var q: QCell);
|
||
|
|
|
||
|
|
implementation
|
||
|
|
|
||
|
|
procedure InitCell(var c: cellItem; x, y: integer);
|
||
|
|
begin
|
||
|
|
c.x := x;
|
||
|
|
c.y := y;
|
||
|
|
c.next := nil
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure QCellInit(var q: QCell);
|
||
|
|
begin
|
||
|
|
q.first := nil;
|
||
|
|
q.last := nil
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure QCellPush(var q: QCell; var c: cellItem);
|
||
|
|
var
|
||
|
|
tmp: cellItemPtr;
|
||
|
|
begin
|
||
|
|
new(tmp);
|
||
|
|
tmp^.x := c.x;
|
||
|
|
tmp^.y := c.y;
|
||
|
|
tmp^.next := nil;
|
||
|
|
if q.last = nil then
|
||
|
|
begin
|
||
|
|
q.first := tmp;
|
||
|
|
q.last := q.first
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
q.last^.next := tmp;
|
||
|
|
q.last := q.last^.next
|
||
|
|
end
|
||
|
|
end;
|
||
|
|
|
||
|
|
function QCellIsEmpty(var q: QCell): boolean;
|
||
|
|
begin
|
||
|
|
QCellIsEmpty := (q.last = nil)
|
||
|
|
end;
|
||
|
|
|
||
|
|
function QCellGet(var q: QCell): cellItemPtr;
|
||
|
|
begin
|
||
|
|
QCellGet := q.first
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure QCellPop(var q: QCell);
|
||
|
|
var
|
||
|
|
removeItem: cellItemPtr;
|
||
|
|
begin
|
||
|
|
removeItem := QCellGet(q);
|
||
|
|
q.first := removeItem^.next;
|
||
|
|
if q.first = nil then
|
||
|
|
q.last := q.first;
|
||
|
|
dispose(removeItem)
|
||
|
|
end;
|
||
|
|
|
||
|
|
end.
|