Generics Collections TQueue (Delphi)
Contents
Description
This example demonstrates the usage of the generic TQueue class.
Code
var
Queue: TQueue<String>;
begin
{ Create a new Queue. }
Queue := TQueue<String>.Create;
{ Enqueue some items to the Queue. }
Queue.Enqueue('John');
Queue.Enqueue('Mary');
Queue.Enqueue('Bob');
Queue.Enqueue('Anna');
Queue.Enqueue('Erica');
{ Show the first enqueued element without modifying the Queue. }
writeln('First enqueued element is: "' + Queue.Peek() + '".');
{ Extract the beginning element: "John". }
Queue.Extract;
{ Reduce the capacity. }
Queue.TrimExcess;
{ The remaining count of elements }
writeln('The queue now contains ' + IntToStr(Queue.Count) + ' elements.');
{ Show the first enqueued element by modifying the Queue. }
writeln('First enqueued element was: "' + Queue.Dequeue() + '".');
{ Clear the Queue. }
Queue.Clear;
{ Destroy the Queue completely. }
Queue.Free;
readln;
end.
Uses
- System.Generics.Collections.TQueue ( fr | de | ja )
- System.Generics.Collections.TQueue.Enqueue ( fr | de | ja )
- System.Generics.Collections.TQueue.Dequeue ( fr | de | ja )
- System.Generics.Collections.TQueue.Extract ( fr | de | ja )
- System.Generics.Collections.TQueue.Peek ( fr | de | ja )
- System.Generics.Collections.TQueue.TrimExcess ( fr | de | ja )
- System.Generics.Collections.TQueue.Clear ( fr | de | ja )
- System.Generics.Collections.TQueue.Count ( fr | de | ja )