[fpc-pascal] Queue integer values

leledumbo leledumbo_cool at yahoo.co.id
Thu Dec 17 09:31:12 CET 2009


> I need a queue that can store integer values. Is there any way to use
TQueue for this task

You can extend TQueue to have a method to insert the integer as pointers.
Ex:

type
  TMyQueue = class(TQueue)
  public
    procedure AddInt(const Integer: i);
  end;

... // implementation

procedure TMyQueue.AddInt(const Integer: i);
var
  p: PInteger;
begin
  New(p);
  p^:=i;
  Add(p);
end;

Just don't forget to Dispose all the contents before destroying the queue or
you'll have memory leak.

> or does a generic queue class exist which I can use?

AFAIR, no. Last time I check, only list and map have been implemented. But
you can make your own, it's not difficult.
-- 
View this message in context: http://old.nabble.com/Queue-integer-values-tp26817366p26824766.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.




More information about the fpc-pascal mailing list