Code essay ....
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Threading.Tasks;
Namespace Stackgetminvalues
{
public class Program
{
public void Main (string[] args)
{
Mystack mystack = new Mystack ();
Mystack.push (1);
Mystack.push (15);
Mystack.push (20);
Mystack.push (0);
Mystack.push (-10);
Mystack.push (50);
Console.WriteLine (Mystack.getminvalue ());
Mystack.pop ();
Console.WriteLine (Mystack.getminvalue ());
Mystack.pop ();
Console.WriteLine (Mystack.getminvalue ());
Console.ReadLine ();
}
}
public class Mystack
{
Public stack<int> Stackdata;
Public stack<int> stackmin;
Public Mystack ()
{
Stackdata = new stack<int> ();
Stackmin = new stack<int> ();
}
public void Push (int number)
{
if (number. GetType ()! = typeof (int)) throw new ArgumentException ("number must be entered");
if (stackdata.count () = = 0)
{
Stackdata.push (number);
Stackmin.push (number);
Return
}
Stackdata.push (number);
if (Stackmin.peek () > number)
{
Stackmin.push (number);
}
}
public int Pop ()
{
if (stackdata.count () = = 0) throw new IndexOutOfRangeException ("Stack object is empty");
var value = Stackdata.pop ();
if (value = = Stackmin.peek ())
{
Stackmin.pop ();
}
return value;
}
public int Getminvalue ()
{
if (stackmin.count () = = 0) throw new IndexOutOfRangeException ("Minimum stack object is empty");
return Stackmin.peek ();
}
}
}
C # stack = Read the minimum value of "1" in the stack at any time