Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Kolejka
- {
- private int size;
- private int[] queue;
- public Kolejka(int size)
- {
- this.size = size;
- queue = new int[size];
- }
- private int head = 0;
- private int tail = 0;
- private int amount = 0;
- public void enqueue(int x)
- {
- if (amount < size)
- {
- queue[tail] = x;
- tail = (tail + 1) % size;
- amount++;
- }
- else
- {
- Console.WriteLine("Brak miejsca w kolejce!");
- }
- }
- public void dequeue()
- {
- if (amount > 0)
- {
- Console.WriteLine(queue[head]);
- head = (head + 1) % size;
- amount--;
- }
- }
- static void Main(string[] args)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement