本文整理汇总了C#中Stack.Last方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Last方法的具体用法?C# Stack.Last怎么用?C# Stack.Last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.Last方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetBracketMismatch
//Returns the location of bracket mismatch
//Rewrite this to make use of better suited container for brackets
public int GetBracketMismatch(string code)
{
Dictionary<char, char> bracketMap = new Dictionary<char, char>()
{ {'{', '}'}, {'(', ')'}, {'[', ']'}, {'<', '>'} };//, {'\'', '\''} }; //{} () [] <> "" ''
Stack<char> bracketStack = new Stack<char>();
int counter = 0;
foreach (char c in code)
{
if("(){}<>".Contains(c))
{
if (!")}>".Contains(c))
{
bracketStack.Push(c);
}
else if (bracketMap.Any(q => q.Key == bracketMap[bracketStack.Last()]))
{
bracketStack.Pop();
}
else
{
return counter;
}
}
counter++;
}
return -1;
}
示例2: Main
static void Main()
{
string input = Console.ReadLine();
if (input.Equals(""))
{
Console.WriteLine("(empty)");
return;
}
string[] charinp = input.Split(' ');
int index = 0;
Stack<int> resiver = new Stack<int>();
for (int i = 0; i < charinp.Length; i++)
{
if (!int.TryParse(charinp[i], out index))
{
Console.WriteLine("Invalid Input");
return;
}
resiver.Push(index);
}
while(resiver.Count>1)
{
int j = resiver.Pop();
Console.Write(j+" ");
}
Console.WriteLine(resiver.Last());
}
示例3: GetSuperTypes
protected virtual void GetSuperTypes(List<Interface> superTypes, Stack<Interface> branch, bool throws = false)
{
branch.Push(this);
foreach (Interface superType in this.SuperInterfaces)
{
// Circular inheritance condition
if (!branch.Contains(superType))
{
// Multiple-path inheritance condition
if (!superTypes.Contains(superType))
{
superTypes.Add(superType);
superType.GetSuperTypes(superTypes, branch, throws);
}
}
else
{
if (throws)
{
throw new InheritanceValidationException(branch.Last());
}
}
}
branch.Pop();
}
示例4: Main
static void Main(string[] args)
{
Stack s = new Stack();
string temp = Console.ReadLine();
int a;
int b;
char x;
for (var i = 0; i <= temp.Length - 1; i++)
{
if ((temp[i] >= '0') && (temp[i] <= '9'))
{
int j = 0;
while ((temp[i + j] >= '0') && (temp[i + j] <= '9'))
{
j++;
}
string str = temp.Substring(i, j);
int k = int.Parse(str);
s.Add(k);
i = i + j-1;
}
else if (temp[i] == ')')
{
b = (int)s.Last();
s.Remove();
x = (char)s.Last();
s.Remove();
a = (int)s.Last();
s.Remove();
s.Remove();
int Rez = Solve(a, b, x);
s.Add((object)Rez);
}
else
{
s.Add(temp[i]);
}
}
Console.WriteLine(s.Last());
}
示例5: CombinePath
private static string CombinePath(Stack<string> path)
{
var parts = new List<string>(3);
parts.Add(path.First());
if (path.Count > 1)
{
if (path.Count > 2)
{
parts.Add("..");
}
parts.Add(path.Last());
}
return string.Join(Path.DirectorySeparatorChar.ToString(), parts);
}
示例6: EmitSSAforArrayDimension
/// <summary>
/// Emits the SSA form of each dimension in the ArrayNode data structure
/// The dimensionNode is updated by the function with the SSA'd dimensions
///
/// Given:
/// dimensionNode -> a[b][c]
/// Outputs:
/// astlist -> t0 = b
/// -> t1 = c
/// dimensionNode -> a[t0][t1]
///
/// </summary>
/// <param name="dimensionNode"></param>
/// <param name="astlist"></param>
private void EmitSSAforArrayDimension(ref ArrayNode dimensionNode, ref List<AssociativeNode> astlist)
{
AssociativeNode indexNode = dimensionNode.Expr;
// Traverse first dimension
Stack<AssociativeNode> localStack = new Stack<AssociativeNode>();
DFSEmitSSA_AST(indexNode, localStack, ref astlist);
AssociativeNode tempIndexNode = localStack.Last();
if (tempIndexNode is BinaryExpressionNode)
{
dimensionNode.Expr = (tempIndexNode as BinaryExpressionNode).LeftNode;
// Traverse next dimension
indexNode = dimensionNode.Type;
while (indexNode is ArrayNode)
{
ArrayNode arrayNode = indexNode as ArrayNode;
localStack = new Stack<AssociativeNode>();
DFSEmitSSA_AST(arrayNode.Expr, localStack, ref astlist);
tempIndexNode = localStack.Last();
if (tempIndexNode is BinaryExpressionNode)
{
arrayNode.Expr = (tempIndexNode as BinaryExpressionNode).LeftNode;
}
indexNode = arrayNode.Type;
}
}
}
示例7: TryEvaluate
internal override bool TryEvaluate(Stack<Context> contextStack, CompilationState state, out Context context)
{
if (_next == null)
{
context = contextStack.Last();
return true;
}
else
{
var rootedContextStack = new Stack<Context>();
rootedContextStack.Push(contextStack.Last());
return _next.TryEvaluate(rootedContextStack, state, out context);
}
}
示例8: GetFileInfoFiles
public static IEnumerable<FileInfo> GetFileInfoFiles(string root, string fileExt)
{
Stack<string> pending = new Stack<string>();
pending.Push(root);
DirectoryInfo direcInfo = new DirectoryInfo(root);
while (pending.Count < 2 && pending.Count != 0)
{
var path = pending.Pop();
FileInfo[] next = null;
try
{
next = direcInfo.GetFiles(fileExt);
}
catch { }
if (next != null && next.Length != 0)
foreach (var file in next) yield return file;
try
{
next = direcInfo.GetFiles(fileExt);
foreach (var subdir in next)
//pending.Push(subdir.FullName);
{
if (pending.Last() != subdir.FullName)
pending.Push(subdir.FullName);
}
}
catch { }
}
}
示例9: GetFiles
public IEnumerable<string> GetFiles(string root)
{
Stack<string> pending = new Stack<string>();
pending.Push(root);
while (pending.Count < 4 && pending.Count != 0)
{
var path = pending.Pop();
string[] next = null;
try
{
next = Directory.GetDirectories(path);
}
catch { }
if (next != null && next.Length != 0)
foreach (var file in next) yield return file;
try
{
next = Directory.GetDirectories(path);
foreach (var subdir in next)
//pending.Push(subdir);
{
if (pending.Last() != subdir)
pending.Push(subdir);
}
}
catch { }
}
}
示例10: StackExtensions_Last_ThrowsExceptionIfStackIsEmpty
public void StackExtensions_Last_ThrowsExceptionIfStackIsEmpty()
{
var stack = new Stack<Int32>();
Assert.That(() => stack.Last(),
Throws.TypeOf<InvalidOperationException>());
}
示例11: StackExtensions_Last_ReturnsLastItemInStack
public void StackExtensions_Last_ReturnsLastItemInStack()
{
var stack = new Stack<Int32>();
stack.Push(3);
stack.Push(2);
stack.Push(1);
var result = stack.Last();
TheResultingValue(result).ShouldBe(3);
}
示例12: StackExtensions_Last_ThrowsExceptionIfStackIsEmpty
public void StackExtensions_Last_ThrowsExceptionIfStackIsEmpty()
{
var stack = new Stack<Int32>();
stack.Last();
}
示例13: ParseTree
private static Haplogroup ParseTree(string filename)
{
var flatTree = ParseFlatTree(filename);
var stack = new Stack<Haplogroup>();
stack.Push(new Haplogroup() { Name = flatTree.First().Key });
Action<string> add = x =>
{
var g = new Haplogroup()
{
Name = x,
Parent = stack.Peek(),
};
stack.Peek().Children.Add(g);
stack.Push(g);
};
var depth = 0;
var filler = 0;
foreach (var node in flatTree.Skip(1))
{
if (node.Value == depth)
{
stack.Pop();
add(node.Key);
}
//else if (node.Value == depth + 1)
else if (node.Value > depth)
{
var delta = node.Value - depth;
depth += delta;
foreach (var f in Enumerable.Range(0, delta - 1))
{
add("FILLER_" + filler++);
}
add(node.Key);
}
//else if (node.Value > depth)
//{
// Console.WriteLine();
//}
else
{
var delta = depth - node.Value;
depth -= delta;
for (var i = 0; i < delta + 1; i++)
{
stack.Pop();
}
add(node.Key);
}
}
return stack.Last();
}