Danielos168

Kolejka by Stos

Jan 19th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace zad2
  8. {
  9.     class Kolejka
  10.     {
  11.         Stack<int> a = new Stack<int>();
  12.         Stack<int> b = new Stack<int>();
  13.  
  14.         public void Dodaj(int n)
  15.         {
  16.  
  17.             a.Push(n);
  18.         }
  19.  
  20.         public int Usun()
  21.         {
  22.             if (b.Count == 0)
  23.             {
  24.                 while(a.Count > 0)
  25.                     b.Push(a.Pop());
  26.             }
  27.  
  28.             return b.Pop();
  29.         }
  30.  
  31.         public int Rozmiar()
  32.         {
  33.             return a.Count + b.Count;
  34.         }
  35.     }
  36.  
  37.  
  38.     class Program
  39.     {
  40.         static void Main(string[] args)
  41.         {
  42.             Kolejka k = new Kolejka();
  43.             k.Dodaj(1);
  44.             k.Dodaj(2);
  45.             k.Usun();
  46.             k.Dodaj(3);
  47.             while (k.Rozmiar() > 0)
  48.             {
  49.                 Console.WriteLine(k.Usun());
  50.             }
  51.  
  52.             Console.ReadKey();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment