-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.cs
35 lines (30 loc) · 897 Bytes
/
Queue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// New Queue of integers.
Queue<int> queue = new Queue<int>();
queue.Enqueue(5);
queue.Enqueue(10);
queue.Enqueue(15);
queue.Enqueue(20);
// Create new array with Length equal to Queue's element count.
int[] array = new int[queue.Count];
// Copy the Queue to the int array.
queue.CopyTo(array, 0);
// Loop through and display int[] in order.
Console.WriteLine("Array:");
for (int i = 0; i < array.Length; i++)
{
Console.WriteLine(array[i]);
}
// Loop through int array in reverse order.
Console.WriteLine("Array reverse order:");
for (int i = array.Length - 1; i >= 0; i--)
{
Console.WriteLine(array[i]);
}
}
}