Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class Kolejka
  2. {
  3. private int size;
  4.  
  5. private int[] queue;
  6.  
  7. public Kolejka(int size)
  8. {
  9. this.size = size;
  10. queue = new int[size];
  11. }
  12.  
  13. private int head = 0;
  14. private int tail = 0;
  15. private int amount = 0;
  16.  
  17.  
  18. public void enqueue(int x)
  19. {
  20. if (amount < size)
  21. {
  22. queue[tail] = x;
  23. tail = (tail + 1) % size;
  24. amount++;
  25. }
  26. else
  27. {
  28. Console.WriteLine("Brak miejsca w kolejce!");
  29. }
  30. }
  31.  
  32. public void dequeue()
  33. {
  34. if (amount > 0)
  35. {
  36. Console.WriteLine(queue[head]);
  37. head = (head + 1) % size;
  38. amount--;
  39. }
  40. }
  41. static void Main(string[] args)
  42. {
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement