Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace stack
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Stack<int> polica = new Stack<int>();
- //Stack<int> polica = new();
- int brojacTanjira = 0;
- while (true)
- {
- Console.WriteLine("Unesi akciju ([p]-pranje/[U]-uzimanje): ");
- string akcija = Console.ReadLine();
- switch (akcija.ToLower())
- {
- case "p":
- case "pranje":
- case "peri":
- brojacTanjira++;
- Console.WriteLine($"pranje tanjira {brojacTanjira}");
- polica.Push(brojacTanjira);
- break;
- case "u":
- case "uzmi":
- case "uzimanje":
- int tanjir;
- /*
- if (polica.TryPop(out tanjir))
- {
- tanjir = polica.Pop();
- Console.WriteLine($"uzimam tanjir {tanjir}");
- brojacTanjira--;
- }
- */
- if (polica.Count() > 0)
- //if (polica.Any())
- {
- tanjir = polica.Pop();
- Console.WriteLine($"uzimam tanjir {tanjir}");
- brojacTanjira--;
- }
- else
- {
- Console.WriteLine("\tnema vise tanjira na polci(steku)");
- }
- break;
- case "k":
- case "kraj":
- Console.WriteLine("\nkraj izvrsavanja");
- return;
- default:
- Console.WriteLine("nepoznato");
- break;
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement