Hi! I want to write a Priority Queue but I can't find a TtdCompareFunc
in order to keep the priority queue properties
This is part of the code that presented this problem:
type
TtdSimplePriQueue1 = class
private
FCompare : TtdCompareFunc;
FList : TList;
protected
function pqGetCount : integer;
public
constructor Create(aCompare : TtdCompareFunc);
destructor Destroy; override;
function Dequeue : pointer;
procedure Enqueue(aItem : pointer);
property Count : integer read pqGetCount;
end;
constructor TtdSimplePriQueue1.Create(aCompare : TdCompareFunc);
begin
inherited Create;
FCompare := aCompare;
FList := TList.Create;
end;
destructor TtdSimplePriQueue1.Destroy;
begin
FList.Free;
inherited Destroy;
end;
function TtdSimplePriQueue1.Dequeue : pointer;
var
Inx : integer;
PQCount : integer;
MaxInx : integer;
MaxItem : pointer;
begin
333
Chapter 9—Priority Queues and Heapsort
PQCount := Count;
if (PQCount = 0) then
Result := nil
else if (PQCount = 1) then begin
Result := FList.List^[0];
FList.Clear;
end
else begin
MaxItem := FList.List^[0];
MaxInx := 0;
for Inx := 1 to pred(PQCount) do
if (FCompare(FList.List^[Inx], MaxItem) > 0) then begin
MaxItem := FList.List^[Inx];
MaxInx := Inx;
end;
Result := MaxItem;
FList.List^[MaxInx] := FList.Last;
FList.Count := FList.Count - 1;
end;
end;
procedure TtdSimplePriQueue1.Enqueue(aItem : pointer);
begin
FList.Add(aItem);
end;
function TtdSimplePriQueue1.pqGetCount : integer;
begin
Result := FList.Count;
end;
This are the messages that the compiler produced:
priority_queue_simple.pas(17,19) Error: Identifier not found
"TtdCompareFunc"
priority_queue_simple.pas(17,33) Error: Error in type definition
priority_queue_simple.pas(25,45) Error: Identifier not found
"TtdCompareFunc"
priority_queue_simple.pas(33,1) Fatal: There were 3 errors compiling
module, stopping
Thanks for your help
Mr. Fahrenheit
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives