Advertisement
Filip13

stack - plates

May 21st, 2024
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | Source Code | 0 0
  1. namespace stack
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             Stack<int> polica = new Stack<int>();
  8.             //Stack<int> polica = new();
  9.  
  10.             int brojacTanjira = 0;
  11.  
  12.             while (true)
  13.             {
  14.                 Console.WriteLine("Unesi akciju ([p]-pranje/[U]-uzimanje): ");
  15.                 string akcija = Console.ReadLine();
  16.  
  17.  
  18.                 switch (akcija.ToLower())
  19.                 {
  20.                     case "p":
  21.                     case "pranje":
  22.                     case "peri":
  23.                         brojacTanjira++;
  24.                         Console.WriteLine($"pranje tanjira {brojacTanjira}");
  25.  
  26.                         polica.Push(brojacTanjira);
  27.  
  28.                         break;
  29.  
  30.                     case "u":
  31.                     case "uzmi":
  32.                     case "uzimanje":
  33.                         int tanjir;
  34.  
  35.                         /*
  36.                         if (polica.TryPop(out tanjir))
  37.                         {
  38.                             tanjir = polica.Pop();
  39.                             Console.WriteLine($"uzimam tanjir {tanjir}");
  40.                             brojacTanjira--;
  41.  
  42.                         }
  43.                         */
  44.  
  45.                         if (polica.Count() > 0)
  46.                         //if (polica.Any())
  47.                         {
  48.                             tanjir = polica.Pop();
  49.                             Console.WriteLine($"uzimam tanjir {tanjir}");
  50.                             brojacTanjira--;
  51.  
  52.                         }
  53.                         else
  54.                         {
  55.                             Console.WriteLine("\tnema vise tanjira na polci(steku)");
  56.                         }
  57.  
  58.                         break;
  59.  
  60.                     case "k":
  61.                     case "kraj":
  62.                         Console.WriteLine("\nkraj izvrsavanja");
  63.                         return;
  64.  
  65.                     default:
  66.                         Console.WriteLine("nepoznato");
  67.                         break;
  68.  
  69.                 }
  70.  
  71.                 Console.WriteLine();
  72.             }
  73.  
  74.  
  75.  
  76.         }
  77.  
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement