Difference between revisions of "Show"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
 
Line 14: Line 14:
 
             }
 
             }
 
</syntaxhighlight>
 
</syntaxhighlight>
Outputs the contents of the queue instance to the standard console output stream.
+
 
 +
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.