本文整理汇总了C#中LinkedQueue类的典型用法代码示例。如果您正苦于以下问题:C# LinkedQueue类的具体用法?C# LinkedQueue怎么用?C# LinkedQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinkedQueue类属于命名空间,在下文中一共展示了LinkedQueue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
LinkedQueue<int> collection = new LinkedQueue<int>();
collection.Enqueue(1);
collection.Enqueue(2);
collection.Enqueue(3);
collection.Enqueue(4);
collection.Enqueue(5);
collection.Enqueue(6);
collection.Enqueue(7);
collection.Enqueue(8);
collection.Enqueue(9);
Console.WriteLine("Total elements: " + collection.Count);
Console.WriteLine(collection.Dequeue());
Console.WriteLine(collection.Dequeue());
Console.WriteLine(collection.Dequeue());
Console.WriteLine(collection.Dequeue());
Console.WriteLine("Total elements: " + collection.Count);
collection.Enqueue(10);
collection.Enqueue(11);
Console.WriteLine(collection.Dequeue());
Console.WriteLine("Total elements: " + collection.Count);
var array = collection.ToArray();
Console.WriteLine(string.Join(", ", array));
}
示例2: EnqueueDequeueElement
public void EnqueueDequeueElement()
{
LinkedQueue<int> testQueue = new LinkedQueue<int>();
Assert.AreEqual(0, testQueue.Count);
testQueue.Enqueue(1);
Assert.AreEqual(1, testQueue.Count);
}
示例3: Main
static void Main()
{
var test = new LinkedQueue<int>();
test.Enqueue(1);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(2);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(3);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(4);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(5);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(6);
Console.WriteLine(string.Join(" ", test.ToArray()));
test.Enqueue(7);
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The queue count: {0}", test.Count);
test.Dequeue();
test.Dequeue();
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The queue count: {0}", test.Count);
Console.WriteLine(test.Peek());
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The queue count: {0}", test.Count);
test.Clear();
Console.WriteLine(string.Join(" ", test.ToArray()));
Console.WriteLine("The queue count: {0}", test.Count);
//test.Dequeue(); //if uncommented this line should throw exception
}
示例4: TestEmptyStackToArray_ShouldReturnEmptyArray
public void TestEmptyStackToArray_ShouldReturnEmptyArray()
{
var stack = new LinkedQueue<DateTime>();
var array = stack.ToArray();
var expected = new DateTime[0];
CollectionAssert.AreEqual(expected, array);
}
示例5: EnumerableTest
[TestMethod] // IEnumerable
public void EnumerableTest()
{
LinkedQueue<object> data = new LinkedQueue<object>();
data.Add(8);
data.Add(13);
data.GetEnumerator();
}
示例6: TestEmptyQueueToArray_ShouldReturnEmptyArray
public void TestEmptyQueueToArray_ShouldReturnEmptyArray()
{
var linkedQueue = new LinkedQueue<int>();
var queueToArray = linkedQueue.ToArray();
Assert.AreEqual(0, queueToArray.Length);
}
示例7: EnqueueAndDequeueSeveralElements1ShouldWorkCorrectly
public void EnqueueAndDequeueSeveralElements1ShouldWorkCorrectly()
{
//Arrange
var queue = new LinkedQueue<int>();
//Assert
Assert.AreEqual(0, queue.Count);
//Act
queue.Enqueue(5);
//Assert
Assert.AreEqual(1, queue.Count);
//Act
queue.Enqueue(6);
//Assert
Assert.AreEqual(2, queue.Count);
//Act
var element = queue.Dequeue();
//Assert
Assert.AreEqual(5, element);
Assert.AreEqual(1, queue.Count);
//Act
element = queue.Dequeue();
//Assert
Assert.AreEqual(6, element);
Assert.AreEqual(0, queue.Count);
}
示例8: TakeTest
[TestMethod] // получение первого элемента
public void TakeTest()
{
LinkedQueue<object> data = new LinkedQueue<object>();
data.Add(8);
data.Add(6);
data.Take();
}
示例9: TestLinkedQueue
private static void TestLinkedQueue()
{
ILinkedQueue<int> linkedQueue = new LinkedQueue<int>();
// Should return true
var isEmpty = linkedQueue.IsEmpty();
linkedQueue.Enqueue(1);
linkedQueue.Enqueue(2);
linkedQueue.Enqueue(3);
linkedQueue.Enqueue(4);
// Should have 4 elements
// Should remove first added element - (1) and return it
var removedElement = linkedQueue.Dequeue();
// Should return first element - (2)
var firstElement = linkedQueue.Peek();
// Should return 3
var count = linkedQueue.Count;
// Should return false
isEmpty = linkedQueue.IsEmpty();
}
示例10: Main
private static void Main(string[] args)
{
ConsoleMio.Setup();
while ((maze = TestMazeFactory.GetNext()) != null)
{
ConsoleMio.PrintHeading("Task 14 Minimal Distances In The Labyrinth Of Doom");
ConsoleMio.WriteLine("Labyrinth Before: ", DarkCyan);
PrintLabyrinth(maze);
ConsoleMio.WriteLine();
unexploredPositions = new LinkedQueue<MatrixPosition>();
DoNextLabyrinth();
ConsoleMio.WriteLine("Labyrinth After: ", DarkGreen);
PrintLabyrinth(maze);
ConsoleMio.WriteLine();
ConsoleMio.WriteLine("Press a key to test the next labyrinth...", DarkRed);
Console.ReadKey(true);
Console.Clear();
}
ConsoleMio.WriteLine(
"Completed!!! Thank you very much for looking all the tasks!",
DarkGreen);
}
示例11: ConvertEmptyQueueToArray
public void ConvertEmptyQueueToArray()
{
LinkedQueue<int> queue = new LinkedQueue<int>();
int[] expected = new int[0];
int[] actual = queue.ToArray();
CollectionAssert.AreEqual(expected, actual);
}
示例12: Test_Enqueue_Dequeue
public void Test_Enqueue_Dequeue()
{
LinkedQueue<int> roo = new LinkedQueue<int>();
Assert.AreEqual(0, roo.Count);
roo.Enqueue(9);
Assert.AreEqual(1, roo.Count);
Assert.AreEqual(9, roo.Dequeue());
Assert.AreEqual(0, roo.Count);
LinkedQueue<string> testEnqueue = new LinkedQueue<string>();
Assert.AreEqual(0, testEnqueue.Count);
for (int i = 1; i <= 1000; i++)
{
testEnqueue.Enqueue("as" + i);
Assert.AreEqual(i, testEnqueue.Count);
}
for (int i = 1; i <= 1000; i++)
{
Assert.AreEqual("as" + i, testEnqueue.Dequeue());
Assert.AreEqual(1000-i, testEnqueue.Count);
}
}
示例13: TestEmptyQueueToArray
public void TestEmptyQueueToArray()
{
var queue = new LinkedQueue<DateTime>();
DateTime[] array = queue.ToArray();
Assert.AreEqual(0, array.Length);
}
示例14: 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
}
示例15: Main
static void Main()
{
LinkedQueue<int> linkedQueue = new LinkedQueue<int>();
LinkedQueue<string> anotherLinkedQueue = new LinkedQueue<string>(
new List<string> { "pesho", "gosho", "sasho", "misho" });
Console.WriteLine(anotherLinkedQueue);
Console.WriteLine("First: " + anotherLinkedQueue.First.Value);
Console.WriteLine("Last: " + anotherLinkedQueue.Last.Value);
Console.WriteLine();
linkedQueue.Enqueue(15);
linkedQueue.Enqueue(20);
Console.WriteLine(linkedQueue);
linkedQueue.Enqueue(50);
linkedQueue.Enqueue(100);
Console.WriteLine(linkedQueue);
anotherLinkedQueue.Dequeue();
Console.WriteLine(anotherLinkedQueue);
linkedQueue.Dequeue();
Console.WriteLine(linkedQueue);
Console.WriteLine(linkedQueue.Peek());
anotherLinkedQueue.Clear();
Console.WriteLine(anotherLinkedQueue.Count == 0 && anotherLinkedQueue.First == null && anotherLinkedQueue.Last == null);
}