Difference between revisions of "Show"
(Created page with "Outputs the contents of the queue instance to the standard console output stream.") |
|||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
− | + | <syntaxhighlight lang=csharp> | |
+ | public void Show() | ||
+ | { | ||
+ | if (Rear != -1) | ||
+ | { | ||
+ | Console.WriteLine(); | ||
+ | Console.Write("The contents of the queue are: "); | ||
+ | foreach (var item in Contents) | ||
+ | { | ||
+ | Console.Write(item); | ||
+ | } | ||
+ | Console.WriteLine(); | ||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | This method first checks that the Rear value is not -1 as an index of -1 would mean the queue is empty, and data cant is take from a queue that is empty. | ||
+ | |||
+ | <syntaxhighlight lang=csharp> | ||
+ | if (Rear != -1) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | The next couple of lines simply print a constant string to the console. | ||
+ | |||
+ | <syntaxhighlight lang=csharp> | ||
+ | foreach (var item in Contents) | ||
+ | { | ||
+ | Console.Write(item); | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | The above section uses a newly declared variable called item to retrieve a letter from the queue one at a time and print it to the console. |
Latest revision as of 13:43, 14 November 2017
public void Show()
{
if (Rear != -1)
{
Console.WriteLine();
Console.Write("The contents of the queue are: ");
foreach (var item in Contents)
{
Console.Write(item);
}
Console.WriteLine();
}
}
This method first checks that the Rear value is not -1 as an index of -1 would mean the queue is empty, and data cant is take from a queue that is empty.
if (Rear != -1)
The next couple of lines simply print a constant string to the console.
foreach (var item in Contents)
{
Console.Write(item);
}
The above section uses a newly declared variable called item to retrieve a letter from the queue one at a time and print it to the console.