随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses Generics.Collections;

procedure TForm1.Button1Click(Sender: TObject);
var
  Queue: TQueue<string>;
  s,str: string;
begin
  Queue := TQueue<string>.Create();

  {入列}
  Queue.Enqueue('AAA');
  Queue.Enqueue('BBB');
  Queue.Enqueue('CCC');
  Queue.Enqueue('DDD');

  {查看}
  str := '';
  for s in Queue do str := str + s + ' ';
  ShowMessage(str); {AAA BBB CCC DDD}

  {出列, 并查看出列元素}
  ShowMessage(Queue.Dequeue); {AAA}

  str := '';
  for s in Queue do str := str + s + ' ';
  ShowMessage(str); {BBB CCC DDD}

  {查看下一个将要出列的是...}
  ShowMessage(Queue.Peek); {BBB}

  Queue.Free;
end;

end.

posted on 2009-10-11 14:21  万一  阅读(...)  评论(...编辑  收藏