Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zad2
- {
- class Kolejka
- {
- Stack<int> a = new Stack<int>();
- Stack<int> b = new Stack<int>();
- public void Dodaj(int n)
- {
- a.Push(n);
- }
- public int Usun()
- {
- if (b.Count == 0)
- {
- while(a.Count > 0)
- b.Push(a.Pop());
- }
- return b.Pop();
- }
- public int Rozmiar()
- {
- return a.Count + b.Count;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Kolejka k = new Kolejka();
- k.Dodaj(1);
- k.Dodaj(2);
- k.Usun();
- k.Dodaj(3);
- while (k.Rozmiar() > 0)
- {
- Console.WriteLine(k.Usun());
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment