vojta249

Stack

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