-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueueClass.cs
More file actions
42 lines (34 loc) · 697 Bytes
/
queueClass.cs
File metadata and controls
42 lines (34 loc) · 697 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.Collections.Generic;
public class Queue<T>
{
private LinkedList<T> _items;
public Queue()
{
_items = new LinkedList<T>();
}
public bool IsEmpty()
{
return _items.Count == 0;
}
public void Enqueue(T item)
{
_items.AddLast(item);
}
public T Dequeue()
{
if (IsEmpty())
{
throw new InvalidOperationException("The queue is empty.");
}
// Get the first item
T value = _items.First.Value;
// Remove the first item
_items.RemoveFirst();
return value;
}
public int Size()
{
return _items.Count;
}
}