-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.cs
More file actions
41 lines (33 loc) · 874 Bytes
/
Queue.cs
File metadata and controls
41 lines (33 loc) · 874 Bytes
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
36
37
38
39
40
41
using System;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FirstCsharp
{
public class Queue<T>
{
private const int Capacity = 100;
private T[] Array = new T[Capacity];
private int Pointer;
public int Count { get { return Pointer; } }
public void Enqueue(T value)
{
if (Pointer == Capacity)
throw new StackOverflowException("Stack overflowed");
Array[Pointer++] = value;
}
public T Dequeue()
{
if (Pointer == 0) return default(T);
var value = Array[0];
Pointer--;
for (var i = 0; i < Pointer; i++)
Array[i] = Array[i + 1];
return value;
}
public bool IsEmpty()
{
return Pointer == 0;
}
}
}