vojta249

Maturita_25 - fronta

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