Generics Collections TQueue (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Language:

Versions:

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

See Also

Personal tools