Line | |
---|
1 | unit GenericQueue;
|
---|
2 |
|
---|
3 | {$mode delphi}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | GenericList;
|
---|
9 |
|
---|
10 | type
|
---|
11 | TGQueue<T> = class
|
---|
12 | private
|
---|
13 | FList: TGList<T>;
|
---|
14 | function GetCount: Integer;
|
---|
15 | public
|
---|
16 | procedure Enqueue(Value: T);
|
---|
17 | procedure EnqueueArray(Values: array of T);
|
---|
18 | procedure EnqueueList(List: TGList<T>);
|
---|
19 | function Dequeue: T;
|
---|
20 | function Peek: T;
|
---|
21 | constructor Create;
|
---|
22 | destructor Destroy; override;
|
---|
23 | property List: TGList<T> read FList;
|
---|
24 | property Count: Integer read GetCount;
|
---|
25 | end;
|
---|
26 |
|
---|
27 |
|
---|
28 | implementation
|
---|
29 |
|
---|
30 | { TGQueue }
|
---|
31 |
|
---|
32 | procedure TGQueue<T>.Enqueue(Value: T);
|
---|
33 | begin
|
---|
34 | FList.Add(Value);
|
---|
35 | end;
|
---|
36 |
|
---|
37 | procedure TGQueue<T>.EnqueueArray(Values: array of T);
|
---|
38 | begin
|
---|
39 | FList.AddArray(Values);
|
---|
40 | end;
|
---|
41 |
|
---|
42 | procedure TGQueue<T>.EnqueueList(List: TGList<T>);
|
---|
43 | begin
|
---|
44 | FList.AddList(List);
|
---|
45 | end;
|
---|
46 |
|
---|
47 | function TGQueue<T>.Peek: T;
|
---|
48 | begin
|
---|
49 | Result := FList.First;
|
---|
50 | end;
|
---|
51 |
|
---|
52 | constructor TGQueue<T>.Create;
|
---|
53 | begin
|
---|
54 | FList := TGList<T>.Create;
|
---|
55 | end;
|
---|
56 |
|
---|
57 | destructor TGQueue<T>.Destroy;
|
---|
58 | begin
|
---|
59 | FList.Free;
|
---|
60 | inherited Destroy;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | function TGQueue<T>.Dequeue: T;
|
---|
64 | begin
|
---|
65 | Result := FList.Extract(FList.First);
|
---|
66 | end;
|
---|
67 |
|
---|
68 | function TGQueue<T>.GetCount: Integer;
|
---|
69 | begin
|
---|
70 | Result := FList.Count;
|
---|
71 | end;
|
---|
72 |
|
---|
73 | end.
|
---|
Note:
See
TracBrowser
for help on using the repository browser.