本文整理汇总了C#中Stack.None方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.None方法的具体用法?C# Stack.None怎么用?C# Stack.None使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.None方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsParenthesisMatch
public static bool IsParenthesisMatch(this string str)
{
if (str.IsNullOrEmpty())
return true;
var stack = new Stack<char>();
for (var i = 0; i < str.Length; i++)
{
var c = str.CharAt(i);
switch (c)
{
case '(':
stack.Push(c);
break;
case '{':
stack.Push(c);
break;
case ')':
if (stack.None())
return false;
if (stack.Peek() == '(')
stack.Pop();
else
return false;
break;
case '}':
if (stack.None())
return false;
if (stack.Peek() == '{')
stack.Pop();
else
return false;
break;
}
}
return stack.None();
}
示例2: ParseBrackets
public static CompositeList<string> ParseBrackets(this string @string)
{
var result = new CompositeList<string>();
var stack = new Stack<Tuple<char, string>>();
var collected = "";
var currentComposite = result;
for (var i = 0; i < @string.Length; i++)
{
var c = @string.CharAt(i);
switch (c)
{
case '(':
stack.Push(c.Pair(collected));
collected = "";
var child = new CompositeList<string>();
currentComposite.AddChild(child);
currentComposite = child;
break;
case '{':
stack.Push(c.Pair(collected));
collected = "";
var child2 = new CompositeList<string>();
currentComposite.AddChild(child2);
currentComposite = child2;
break;
case ')':
if (stack.None())
return result;
if (stack.Peek().Item1 == '(')
{
currentComposite.Content = collected;
collected = stack.Pop().Item2;
currentComposite = (CompositeList<string>)currentComposite.Parent;
}
else
return result;
break;
case '}':
if (stack.None())
return result;
if (stack.Peek().Item1 == '{')
{
currentComposite.Content = collected;
collected = stack.Pop().Item2;
currentComposite = (CompositeList<string>)currentComposite.Parent;
}
else
return result;
break;
default:
collected += c;
break;
}
}
currentComposite.Content = collected;
return result;
}