本文整理汇总了C#中Stack.Min方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Min方法的具体用法?C# Stack.Min怎么用?C# Stack.Min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.Min方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
int[] inputNums = Console.ReadLine().Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse).ToArray();
int[] array = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse).ToArray();
var stack = new Stack<int>();
for (int i = 0; i < array.Length; i++)
{
stack.Push(array[i]);
}
for (int i = 0; i < inputNums[1]; i++)
{
stack.Pop();
}
if (stack.Contains(inputNums[2]))
{
Console.WriteLine("true");
}
else if (!stack.Contains(inputNums[2]) && stack.Count > 0)
{
Console.WriteLine(stack.Min());
}
else
{
Console.WriteLine(0);
}
}
示例2: Main
static void Main(string[] args)
{
// Take main input
int[] input = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
Stack<int> stack = new Stack<int>();
int push = input.First();
int pop = input[1];
int find = input.Last();
// Fill the stack
int[] stackInput = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
for (int i = 0; i < push; i++)
{
stack.Push(stackInput[i]);
}
// Pop the stack
for (int i = 0; i < pop; i++)
{
if (stack.Count > 0)
{
stack.Pop();
}
}
// Output
if (stack.Contains(find))
{
Console.WriteLine("true");
}
else
{
Console.WriteLine(stack.Count > 0 ? stack.Min() : 0);
}
}
示例3: PrintResult
private static void PrintResult(Stack<int> stackNumber, List<int> commands)
{
if (stackNumber.Count <= 0)
{
Console.WriteLine(0);
return;
}
bool isContains = stackNumber.Contains(commands[2]);
if (isContains)
{
Console.WriteLine("true");
}
else
{
int minValue = stackNumber.Min();
Console.WriteLine(minValue);
}
}
示例4: Main
public static void Main()
{
//commands:
//first number = amount of elements to push into the stack
// second number = amount of elements to pop from the stack
//third number = element to check if is contained in the stack
int[] commandNumbers =
Console.ReadLine()
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.ToArray();
int[] inputNumbers =
Console.ReadLine()
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
.Select(int.Parse)
.ToArray();
Stack<int> numbers = new Stack<int>();
for (int i = 0; i < commandNumbers[0]; i++)
{
numbers.Push(inputNumbers[i]);
}
for (int i = 0; i < commandNumbers[1]; i++)
{
numbers.Pop();
}
if (numbers.Count <= 0)
{
Console.WriteLine(0);
}
else if (numbers.Contains(commandNumbers[2]))
{
Console.WriteLine(true);
}
else
{
Console.WriteLine(numbers.Min());
}
}
示例5: Main
static void Main(string[] args)
{
int[] arguments = Console.ReadLine()
.Split()
.Select(int.Parse)
.ToArray();
int[] itemsToPush = Console.ReadLine()
.Split()
.Select(int.Parse)
.ToArray();
Stack<int> stk=new Stack<int>();
for (int i = 0; i < arguments[0]; i++)
{
stk.Push(itemsToPush[i]);
}
for (int i = 0; i < arguments[1]; i++)
{
stk.Pop();
}
if (stk.Contains(arguments[2]))
{
Console.WriteLine("true");
}
else
{
if (stk.Count > 0)
{
Console.WriteLine(stk.Min());
}
else
{
Console.WriteLine(0);
}
}
}
示例6: StackExtensions_Min_ThrowsExceptionIfStackIsEmpty
public void StackExtensions_Min_ThrowsExceptionIfStackIsEmpty()
{
var stack = new Stack<Int32>();
Assert.That(() => stack.Min(),
Throws.TypeOf<InvalidOperationException>());
}
示例7: StackExtensions_Min_ReturnsMinValue
public void StackExtensions_Min_ReturnsMinValue()
{
var stack = new Stack<Int32>();
stack.Push(4);
stack.Push(5);
stack.Push(6);
stack.Push(99);
stack.Push(10);
stack.Push(1);
stack.Push(12);
stack.Push(45);
var result = stack.Min();
TheResultingValue(result).ShouldBe(1);
}
示例8: StackExtensions_Min_ThrowsExceptionIfStackIsEmpty
public void StackExtensions_Min_ThrowsExceptionIfStackIsEmpty()
{
var stack = new Stack<Int32>();
stack.Min();
}