Advertisement
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 ConsoleApp42
- {
- class Program
- {
- static void Main(string[] args)
- {
- Stack<int> s = new Stack<int>();
- Random r = new Random();
- for (int i = 0; i < 10; i++)
- {
- s.Push(r.Next(0,100));
- }
- Stack<int> s1 = OdwrocStos(s);
- Console.ReadKey();
- }
- static Stack<int> OdwrocStos(Stack<int> s)
- {
- Queue<int> temp = new Queue<int>();
- Console.WriteLine("Stos przed odwróceniem");
- while (s.Count != 0)
- {
- int tmp = s.Pop();
- temp.Enqueue(tmp);
- Console.Write(tmp + ",");
- }
- Console.WriteLine();
- while (temp.Count != 0)
- {
- int tmp = temp.Dequeue();
- s.Push(tmp);
- }
- Console.WriteLine("Po odwróceniu: ");
- while (s.Count != 0)
- {
- int tmp = s.Pop();
- temp.Enqueue(tmp);
- Console.Write(tmp + ",");
- }
- return s;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement