Key points
using System;
namespace GenericMyOwnQueue
{
class MyQueue
{
private readonly int[] _items;
private int _currentindex=-1;
public MyQueue() => _items = new int[10];
public void Enqueue(int item) => _items[++_currentindex] = item;
public int Dequeue(int count,int decreasedCount)
{
_currentindex--;
var item=_items[count - decreasedCount];
return item;
}
public int Count => _currentindex + 1;
}
class Program
{
static void Main(string[] args)
{
MyQueue queueObj = new MyQueue();
queueObj.Enqueue(5);
queueObj.Enqueue(15);
queueObj.Enqueue(25);
queueObj.Enqueue(35);
queueObj.Enqueue(45);
int count = queueObj.Count;
while (queueObj.Count > 0)
{
var item = queueObj.Dequeue(count, queueObj.Count);
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
5
15
25
35
45