Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Marjorie L.

Fonte
BSCpE

CODE:

using System;
using System.Collections;
using System.Collections.Generic;

class MyQueue
{
public class quizbeecompetition : CollectionBase
{
public static void Main()
{

Queue<string> ranking = new Queue<string>();


ranking.Enqueue("Champion");
ranking.Enqueue("First");
ranking.Enqueue("Second");
ranking.Enqueue("Third");
ranking.Enqueue("Fourth");

foreach (string rank in ranking)


{
Console.WriteLine(rank);
}

Console.WriteLine("\nRemoving'{0}'", ranking.Dequeue());
Console.WriteLine("Peek the next item to remove: {0}",
ranking.Peek());
Console.WriteLine("Removing: '{0}'", ranking.Dequeue());

Queue<string> queueCopy = new Queue<string>(ranking.ToArray());

Console.WriteLine("\nContents of the First Copy:");


foreach (string position in queueCopy)
{
Console.WriteLine(position);
}
string[] array = new string[ranking.Count * 2];
ranking.CopyTo(array, ranking.Count);

Queue<string> queueCopy2 = new Queue<string>(array);

Console.WriteLine("\nContents of the Second Copy:");


foreach (string number in queueCopy2)
{
Console.WriteLine(number);
}

Console.WriteLine("\nIs result contains Fourth? {0}",


queueCopy.Contains("Fourth"));

Console.WriteLine("\nqueueCopy.Clear()");
queueCopy.Clear();
Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count);

Console.WriteLine("\nSTOP");

You might also like