Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Queue
- {
- QueueItem head;
- QueueItem tail;
- public void Enqueue(int value)
- {
- var item = new QueueItem { Value = value, Next = null };
- if (head == null)
- {
- tail = item;
- head = item;
- }
- else
- {
- tail.Next = item;
- tail = item;
- }
- }
- public int Dequeue()
- {
- if (head == null)
- {
- throw new InvalidOperationException();
- }
- var result = head.Value;
- head = head.Next;
- if (head == null)
- {
- tail = null;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement