Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Kolos_Algorytmy_v2
  8. {
  9.     class Queue
  10.     {
  11.         int?[] array;
  12.         int head = 0, tail = 0, size = 0;
  13.         public Queue(int size)
  14.         {
  15.             array = new int?[size];
  16.         }
  17.  
  18.         public void Enque(int number)
  19.         {
  20.             if (size != array.Length)
  21.             {
  22.                 size++;
  23.                 array[tail++] = number;
  24.                 tail = tail % array.Length;
  25.             }
  26.         }
  27.  
  28.         public int? Deque()
  29.         {
  30.             int? back= null;
  31.             if (size != 0)
  32.             {
  33.                 back = array[head];
  34.                 array[head] = null;
  35.                 size--;
  36.                 head = (head + 1) % array.Length;
  37.  
  38.             }
  39.             return back;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement