Advertisement
vencinachev

QueueToStackNums

Oct 12th, 2020
2,605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program
  5. {
  6.     public static void Main()
  7.     {
  8.         Queue<int> numbersq = new Queue<int>();
  9.         Stack<int> odds = new Stack<int>();
  10.         Stack<int> evens = new Stack<int>();
  11.        
  12.         Console.Write("Enter n: ");
  13.         int n = int.Parse(Console.ReadLine());
  14.        
  15.         for (int i = 0; i < n; i++)
  16.         {
  17.             int num = int.Parse(Console.ReadLine());
  18.             numbersq.Enqueue(num);
  19.         }
  20.        
  21.         while (numbersq.Count != 0)
  22.         {
  23.             int num = numbersq.Dequeue();
  24.             if (num % 2 == 0)
  25.             {
  26.                 evens.Push(num);
  27.             }
  28.             else
  29.             {
  30.                 odds.Push(num);
  31.             }
  32.         }
  33.        
  34.         Console.Write("Odd stack: ");
  35.         while (odds.Count != 0)
  36.         {
  37.             Console.Write(odds.Pop() + ", ");
  38.         }
  39.        
  40.         Console.Write("\nEven stack: ");
  41.         while (evens.Count != 0)
  42.         {
  43.             Console.Write(evens.Pop() + ", ");
  44.         }
  45.        
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement