Description |
The value of the current item at the beginning of the current Queue is returned, but not removed from the Queue. Use of DeQueue returns the value and removes the item from teh Queue.
|
|
Microsoft MSDN Links |
System.Collections
System.Collections.Queue
|
|
|
Illustrating how Peek does not update the Queue |
program Project1;
{$APPTYPE CONSOLE}
uses
System.Collections;
var
MyQueue : System.Collections.Queue;
Enumerator : IEnumerator;
begin
// Create our queue
MyQueue := Queue.Create;
// Add entries to the queue
MyQueue.EnQueue('First');
MyQueue.EnQueue('Second');
MyQueue.Enqueue('Third');
// Display the queue
Console.WriteLine('Queue contains :');
Console.WriteLine;
Enumerator := MyQueue.GetEnumerator;
while enumerator.MoveNext do
Console.WriteLine(Enumerator.Current.ToString);
// Show the next item to be DeQueued
Console.WriteLine;
Console.WriteLine('Peeking at the next item to be DeQueued :');
Console.WriteLine;
Console.WriteLine(MyQueue.Peek.ToString);
Console.WriteLine;
Console.WriteLine('Show that the Queue is unaffacted :');
Console.WriteLine;
Enumerator := MyQueue.GetEnumerator;
while enumerator.MoveNext do
Console.WriteLine(Enumerator.Current.ToString);
Console.Readline;
end.
| Show full unit code | Queue contains :
First
Second
Third
Peeking at the next item to be DeQueued :
First
Show that the Queue is unaffacted :
First
Second
Third
|
|
|
|