本文整理汇总了C#中LinkedQueue.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# LinkedQueue.Contains方法的具体用法?C# LinkedQueue.Contains怎么用?C# LinkedQueue.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedQueue
的用法示例。
在下文中一共展示了LinkedQueue.Contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
// TODO: Epxlain the tests
Console.WriteLine("Testing custom queue class.");
Console.WriteLine("Class features:");
Console.WriteLine(" - linked list implementation");
Console.WriteLine(" - methods Enqueue, Dequeue, Peek, Contains and property Count.");
Console.WriteLine();
Console.WriteLine("Creating a LinkedQueue.");
LinkedQueue<int> queue = new LinkedQueue<int>();
Console.WriteLine("DONE!" + Environment.NewLine);
Console.WriteLine("Enqueuing numbers from 1 to 10");
for (int i = 1; i <= 10; i++)
{
queue.Enqueue(i);
}
Console.WriteLine("DONE!" + Environment.NewLine);
Console.WriteLine("Printing queue using custom enumerator:");
Print(queue);
Console.WriteLine("Peeking: " + queue.Peek());
Console.WriteLine();
Console.WriteLine("Dequeuing 7 elements");
for (int i = 0; i < 7; i++)
{
queue.Dequeue();
}
Console.Write("Press any key to continue testing.");
Console.ReadKey();
Console.WriteLine();
Console.WriteLine("Printing queue:");
Print(queue);
Console.WriteLine("Enqueuing numbers from 1 to 10");
for (int i = 1; i <= 10; i++)
{
queue.Enqueue(i);
}
Console.WriteLine("Peeking: " + queue.Peek());
Console.WriteLine();
Console.WriteLine("Printing queue:");
Print(queue);
Console.WriteLine("Cheking if queue contains the number 5: " + queue.Contains(5));
Console.WriteLine("Cheking if queue contains the number -15: " + queue.Contains(-15));
Console.WriteLine();
Console.WriteLine("Clearing the queue");
queue.Clear();
Console.WriteLine("Cleared");
Console.WriteLine();
Console.WriteLine("Printing queue:");
Print(queue);
try
{
Console.WriteLine("Peeking: ");
queue.Peek();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
示例2: Main
static void Main()
{
LinkedQueue<string> names = new LinkedQueue<string>();
names.Enqueue("Misho");
names.Enqueue("Birata");
Console.WriteLine(names.Dequeue());
Console.WriteLine(names.Peek());
Console.WriteLine(names.Count());
Console.WriteLine(names.Contains("Misho"));
Console.WriteLine(names.Contains("Birata"));
}
示例3: Main
/*
* Implement the ADT queue as dynamic linked list.
* Use generics (LinkedQueue<T>) to allow storing different data types in the queue.
*/
static void Main(string[] args)
{
ILinkedQueue<int> sample = new LinkedQueue<int>();
sample.Enqueue(1);
sample.Enqueue(2);
sample.Enqueue(3);
int[] sampleAsArray = sample.ToArray();
Console.WriteLine("Queue as array:");
for (int index = 0; index < sampleAsArray.Length; index++)
{
Console.WriteLine(sampleAsArray[index]);
}
Console.WriteLine("Dequeue + Peek");
Console.WriteLine(sample.Dequeue() + " Dequeue");
Console.WriteLine(sample.Dequeue() + " Dequeue");
Console.WriteLine(sample.Peek() + " Peek");
Console.WriteLine(sample.Dequeue() + " Dequeue");
sample.Enqueue(4);
Console.WriteLine("Does Contains 4? " + sample.Contains(4));
sample.Enqueue(5);
sample.Enqueue(6);
sample.Clear();
Console.WriteLine("Count after clear: " + sample.Count);
// Console.WriteLine(sample.Dequeue()); // exception expected
}
示例4: Main
static void Main()
{
try
{
LinkedQueue<string> queue = new LinkedQueue<string>();
queue.Enqueue("Message One");
queue.Enqueue("Message Two");
queue.Enqueue("Message Three");
queue.Enqueue("Message Four");
Console.WriteLine(queue.Peek());
Console.WriteLine(queue.Contains("Message Three"));
var array = queue.ToArray();
Console.WriteLine(string.Join(", ", array));
while (queue.Count > 0)
{
string message = queue.Dequeue();
Console.WriteLine(message);
}
queue.Dequeue();
}
catch (IndexOutOfRangeException iex)
{
Console.WriteLine(iex.TargetSite + " -> " + iex.Message);
}
catch (NullReferenceException nex)
{
Console.WriteLine(nex.TargetSite + " -> " + nex.Message);
}
}
示例5: Main
public static void Main()
{
// Create LinkedQueue and test its methods
QueueItem<string> element = new QueueItem<string>("a");
LinkedQueue<string> queue = new LinkedQueue<string>(element);
queue.Enqueue(new QueueItem<string>("b"));
queue.Enqueue(new QueueItem<string>("c"));
queue.Enqueue(new QueueItem<string>("d"));
queue.Enqueue(new QueueItem<string>("e"));
QueueItem<string> firstElement = queue.Dequeue();
QueueItem<string> newFirstElement = queue.Peek();
int count = queue.Count();
bool hasElement = queue.Contains(new QueueItem<string>("z"));
}