Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. public class Queue
  2. {
  3. QueueItem head;
  4. QueueItem tail;
  5.  
  6. public void Enqueue(int value)
  7. {
  8. var item = new QueueItem { Value = value, Next = null };
  9. if (head == null)
  10. {
  11. tail = item;
  12. head = item;
  13. }
  14. else
  15. {
  16. tail.Next = item;
  17. tail = item;
  18. }
  19. }
  20.  
  21. public int Dequeue()
  22. {
  23. if (head == null)
  24. {
  25. throw new InvalidOperationException();
  26. }
  27. var result = head.Value;
  28. head = head.Next;
  29. if (head == null)
  30. {
  31. tail = null;
  32. }
  33. return result;
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement