vojta249

Queue

Mar 30th, 2022 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Fronta
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Hello World!");
  10.  
  11.             fronta frontal = new fronta(15);
  12.             Console.WriteLine(frontal.isempty());
  13.             frontal.enqueue(50);
  14.             frontal.peek();
  15.             frontal.enqueue(15);
  16.             frontal.dequeue();
  17.             frontal.peek();
  18.         }
  19.     }
  20. }
  21.  
  22.  
  23.  
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Linq;
  27. using System.Text;
  28. using System.Threading.Tasks;
  29.  
  30. namespace Fronta
  31. {
  32.     class fronta
  33.     {
  34.         private int[] fronticka = new int[0];
  35.         private bool prazdnota;
  36.         private int index = 0;
  37.         private int start = 0;
  38.        
  39.         public fronta(int n)
  40.         {
  41.             fronticka = new int[n];
  42.         }
  43.  
  44.         public bool isempty()
  45.         {
  46.             prazdnota = true;
  47.             if (index == start)
  48.             {
  49.                 prazdnota = false;
  50.             }
  51.             return prazdnota;
  52.         }
  53.  
  54.         public void enqueue(int prvek)
  55.         {
  56.                 fronticka[index] = prvek;
  57.                 index++;
  58.         }
  59.  
  60.         public void peek()
  61.         {
  62.             Console.WriteLine(fronticka[index - 1]);
  63.         }
  64.  
  65.         public void dequeue()
  66.         {
  67.             fronticka[start] = 0;
  68.             start++;
  69.         }
  70.     }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment