Advertisement
silvana1303

basi queue operations

Sep 20th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace advanced
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int numberPop = numbers[1];
  13.             int numberPeek = numbers[2];
  14.  
  15.             int minEl = int.MaxValue;
  16.  
  17.             int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  18.  
  19.             //Stack<int> stack = new Stack<int>(input);
  20.             Queue<int> queue = new Queue<int>(input);
  21.  
  22.             //for (int i = 0; i < input.Length; i++)
  23.             //{
  24.             //    for (int j = 0; j < numberPush; j++)
  25.             //    {
  26.             //        stack.Push(input[i]);
  27.             //    }
  28.             //}
  29.  
  30.             for (int i = 0; i < numberPop; i++)
  31.             {
  32.                 queue.Dequeue();
  33.             }
  34.  
  35.             if (queue.Contains(numberPeek))
  36.             {
  37.                 Console.WriteLine("true");
  38.             }
  39.             else if(queue.Count == 0)
  40.             {
  41.                 Console.WriteLine("0");
  42.             }
  43.             else
  44.             {
  45.                 //    for (int i = 0; i < input.Length; i++)
  46.                 //    {
  47.                 //        if (input[i] < minEl)
  48.                 //        {
  49.                 //            minEl = input[i];
  50.                 //        }
  51.                 //    }
  52.  
  53.                 foreach (var item in queue)
  54.                 {
  55.                     if (item < minEl)
  56.                     {
  57.                       minEl = item;
  58.                     }
  59.                 }
  60.  
  61.                 Console.WriteLine(minEl);
  62.             }
  63.         }
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement