本文整理汇总了C#中Stack.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Reverse方法的具体用法?C# Stack.Reverse怎么用?C# Stack.Reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.Reverse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoInterpretNextInstructionStackTypes
protected override void DoInterpretNextInstructionStackTypes(IDictionary<int, ILOpCode> aOpCodes, Stack<Type> aStack, ref bool aSituationChanged, int aMaxRecursionDepth)
{
foreach (var xTarget in BranchLocations)
{
base.InterpretInstruction(xTarget, aOpCodes, new Stack<Type>(aStack.Reverse()), ref aSituationChanged, aMaxRecursionDepth);
}
base.DoInterpretNextInstructionStackTypes(aOpCodes, new Stack<Type>(aStack.Reverse()), ref aSituationChanged, aMaxRecursionDepth);
}
示例2: Convert
public string Convert(string expression)
{
var tokens = _infixLexer.Analyze(expression, true);
var operators = new Stack<string>();
var output = new Stack<string>();
foreach (var token in tokens)
{
if (IsInfixOperator(token))
{
if (IsRightBracket(token))
{
if (!ContainsLeftBracket(operators))
throw new ArgumentException("Infix expression parsing error. Incorrect nesting.");
PopNestedOperators(operators, output);
PopCorrespondingUnaryOperators(operators, output);
}
else
operators.Push(token);
}
else
{
output.Push(token);
PopCorrespondingUnaryOperators(operators, output);
}
}
if (operators.Count > 0 && ContainsLeftBracket(operators))
throw new ArgumentException("Infix expression parsing error. Incorrect nesting.");
PopRemainingOperators(operators, output);
return string.Join(" ", output.Reverse());
}
示例3: NormalizePath
public static string NormalizePath(string path)
{
var isNetworkSharePath = path.StartsWith(@"\\");
var slashes = new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar };
var parts = path.Split(slashes, StringSplitOptions.RemoveEmptyEntries);
var stack = new Stack<string>();
foreach (var part in parts)
{
if (part == "..")
{
if (stack.Count > 0)
{
stack.Pop();
}
else
{
throw new ArgumentException("Too many \"..\" in the path \"" + path + "\".");
}
}
else if (part != ".")
{
stack.Push(part);
}
}
if (isNetworkSharePath)
{
return @"\\" + string.Join(@"\", stack.Reverse().ToArray());
}
else
{
return string.Join("/", stack.Reverse().ToArray());
}
}
示例4: Recurse
static void Recurse(int k, int depth, string[] elements, Stack<string> stack)
{
if (stack.Count == k)
{
Console.Write("(");
Console.Write(string.Join(" ", stack.Reverse()));
Console.WriteLine(")");
}
else
{
int remaining = elements.Length - depth;
if (stack.Count + remaining < k)
return;
// take element
stack.Push(elements[depth]);
Recurse(k, depth + 1, elements, stack);
stack.Pop();
// drop element
if (stack.Count + remaining - 1 < k)
return;
Recurse(k, depth + 1, elements, stack);
}
}
示例5: DoTest
private static void DoTest(List<Item> testData, ISymbolTable symbolTable)
{
Stack<Item> inserted = new Stack<Item>(testData.Count);
Random r = new Random(DateTime.Now.Millisecond);
DateTime start = DateTime.Now;
foreach (Item item in testData)
{
symbolTable.Insert(item);
inserted.Push(item);
}
foreach (Item item in inserted.Reverse())
{
Item found = symbolTable.Search(item.Key);
if (!found.Value.Equals(item.Value))
{
throw new Exception();
}
}
for (int i = 0; i < testData.Count; i++)
{
int randomIndex = r.Next(testData.Count);
Item searched = testData[randomIndex];
Item found = symbolTable.Search(searched.Key);
if (!found.Value.Equals(searched.Value))
{
throw new Exception();
}
}
DateTime finish = DateTime.Now;
TimeSpan span = finish - start;
Console.WriteLine("Timing for {0}: {1} ms", symbolTable.GetType(), span.TotalMilliseconds);
}
示例6: Solve
static void Solve(Stack<int> stack, int index)
{
if (index == -1)
{
return;
}
if (stack.Sum() == target)
{
Console.WriteLine(string.Join(", ", stack.Reverse()));
return;
}
else
{
if (stack.Sum() + coins[index] <= target)
{
stack.Push(coins[index]);
}
else
{
index--;
}
Solve(stack, index);
}
}
示例7: ReadPassword
/// <summary>
/// Like System.Console.ReadLine(), only with a mask.
/// </summary>
/// <param name="mask">a <c>char</c> representing your choice of console mask</param>
/// <returns>the string the user typed in </returns>
public static string ReadPassword(char mask)
{
const int ENTER = 13, BACKSP = 8, CTRLBACKSP = 127;
int[] filtered = { 0, 27, 9, 10 /*, 32 space, if you care */ }; // const
var pass = new Stack<char>();
char chr;
while ((chr = Console.ReadKey(true).KeyChar) != ENTER) {
if (chr == BACKSP) {
if (pass.Count > 0) {
Console.Write("\b \b");
pass.Pop();
}
}
else if (chr == CTRLBACKSP) {
while (pass.Count > 0) {
Console.Write("\b \b");
pass.Pop();
}
}
else if (filtered.Count(x => chr == x) > 0) { }
else {
pass.Push(chr);
Console.Write(mask);
}
}
Console.WriteLine();
return new string(pass.Reverse().ToArray());
}
示例8: CanonicalizePath
/// <summary>
/// Splits the given path into segments and resolves any parent path references
/// it can (eg. "foo/../bar" becomes "bar" whereas "../foo" is left as-is).
/// </summary>
private static string CanonicalizePath(string path, string currentDirectory)
{
var pathStack = new Stack<string>();
// Split assuming we might get any combination of backward and forward slashes
string[] segments = path.Split('\\', '/');
foreach (string segment in segments)
{
// If the parent reference is the first one on the stack, do nothing
// (because there's nothing we can do, and removing it would break the path)
if (segment.Equals("..") && pathStack.Count > 0 && pathStack.Peek() != "..")
pathStack.Pop();
else
pathStack.Push(segment);
}
IEnumerable<string> pathList = pathStack.Reverse().ToList();
// if the imported file is outside the path of the first file then
// path re-writing won't work.. so we can check to see if we can further
// reduce the path. e.g.
//
// base/css/a.less
// @import "../../theme/b.less";
// theme/b.less
// url("../base/file.png")
//
// then we end up with ../../base/file.png
// which we re-write as ../file.png
if (pathList.First().Equals(".."))
{
// get the total number of parent segments (../) in the path list
var numberOfParents = pathList.TakeWhile(segment => segment.Equals("..")).Count();
// get the relevant part of the current directory that the ../ goes down too
var currentPathList = currentDirectory
.Split('\\', '/')
.Reverse()
.Take(numberOfParents)
.Reverse();
// now see how many match going outwards
int numberOfMatchingParents = 0, i = numberOfParents;
foreach (var currentPathSegment in currentPathList)
{
if (i < pathList.Count() && string.Equals(currentPathSegment, pathList.ElementAt(i++), StringComparison.InvariantCultureIgnoreCase))
{
numberOfMatchingParents++;
}
}
// skip out the ../ that match directories we are already in
pathList = pathList.Take(numberOfParents - numberOfMatchingParents)
.Concat(pathList.Skip((numberOfParents - numberOfMatchingParents) + (numberOfMatchingParents*2)));
}
// Recombine the path segments. Note that there is a difference between doing this
// and pathStack.Reverse().Aggregate("", Path.Combine), which would discard empty path
// segments (and therefore strip leading slashes)
return string.Join("/", pathList.ToArray());
}
示例9: FindAllPaths
private static void FindAllPaths(int row, int col, Stack<Tuple<int, int>> path)
{
path.Push(new Tuple<int, int>(row, col));
visited[row, col] = true;
if (row == endRow && col == endCol)
{
Console.WriteLine(string.Join(string.Empty, path.Reverse()));
count++;
}
else
{
for (int dir = 0; dir < 4; dir++)
{
int nextRow = row + dRow[dir];
int nextCol = col + dCol[dir];
if (IsInsideMatrix(nextRow, nextCol) &&
matrix[nextRow][nextCol] != Impassable &&
!visited[nextRow, nextCol])
{
FindAllPaths(nextRow, nextCol, path);
}
}
}
visited[row, col] = false;
path.Pop();
}
示例10: GetPath
private static void GetPath(char[,] matrix, Cell start, Cell end, Stack<Cell> path)
{
if (start.Row >= matrix.GetLength(0) || start.Row < 0 || start.Col >= matrix.GetLength(1) || start.Col < 0)
{
return; // the cell is outside the matrix
}
if (matrix[start.Row, start.Col] == '*')
{
return; // the cell is not passable
}
if (start.Equals(end))
{
path.Push(end);
Console.WriteLine("Path: {0}", string.Join(" ", path.Reverse())); // found exit
path.Pop();
return;
}
matrix[start.Row, start.Col] = '*';
path.Push(start);
GetPath(matrix, new Cell(start.Row + 1, start.Col), end, path);
GetPath(matrix, new Cell(start.Row, start.Col + 1), end, path);
GetPath(matrix, new Cell(start.Row - 1, start.Col), end, path);
GetPath(matrix, new Cell(start.Row, start.Col - 1), end, path);
matrix[start.Row, start.Col] = ' ';
path.Pop();
}
示例11: ResolveFluentMethod
private static void ResolveFluentMethod(ExportSettings settings)
{
if (string.IsNullOrEmpty(_parameters.ConfigurationMethod)) return;
var methodPath = _parameters.ConfigurationMethod;
var path = new Stack<string>(methodPath.Split('.'));
var method = path.Pop();
var fullQualifiedType = string.Join(".", path.Reverse());
foreach (var sourceAssembly in settings.SourceAssemblies)
{
var type = sourceAssembly.GetType(fullQualifiedType, false);
if (type != null)
{
var constrMethod = type.GetMethod(method);
if (constrMethod != null && constrMethod.IsStatic)
{
var pars = constrMethod.GetParameters();
if (pars.Length == 1 && pars[0].ParameterType == typeof(ConfigurationBuilder))
{
settings.ConfigurationMethod = builder => constrMethod.Invoke(null, new object[] { builder });
break;
}
}
}
}
}
示例12: FindPath
private static bool FindPath(int row, int col, Stack<Tuple<int, int>> path)
{
path.Push(new Tuple<int, int>(row, col));
visited[row, col] = true;
if (row == endRow && col == endCol)
{
Console.WriteLine(string.Join("->", path.Reverse()));
return true;
}
for (int dir = 0; dir < 4; dir++)
{
int nextRow = row + dRow[dir];
int nextCol = col + dCol[dir];
if (IsInsideMatrix(nextRow, nextCol) &&
matrix[nextRow][nextCol] != Impassable &&
!visited[nextRow, nextCol])
{
if (FindPath(nextRow, nextCol, path))
{
return true;
}
}
}
path.Pop();
visited[row, col] = false;
return false;
}
示例13: GetLines
public IEnumerable<TokenBlockBase> GetLines(BookTokenIterator bookTokens, string lastText, int firstTokenID,
int stopTokenID = -1, string stopText = null)
{
_firstTokenID = firstTokenID;
_tree = bookTokens.BuildTree(_firstTokenID);
_lastOpenTag = _tree.Peek();
_fontSize = GetCurrentFontSize();
_separator = false;
bool firstText = true;
_marginLeft = _marginRight = 0.0;
foreach (TagOpenToken openTagToken in _tree.Reverse())
EnterMargin(openTagToken.TextProperties);
if (string.IsNullOrEmpty(stopText) && stopTokenID > 0)
--stopTokenID;
while (bookTokens.MoveNext())
{
foreach (TokenBlockBase baseTokenLine in OutputLines(false))
yield return baseTokenLine;
if (!Append(bookTokens, lastText, stopTokenID, stopText, ref firstText))
break;
}
foreach (TokenBlockBase baseTokenLine in OutputLines(true))
yield return baseTokenLine;
}
示例14: PrintRods
private static void PrintRods(Stack<int> source, Stack<int> destination, Stack<int> spare)
{
Console.WriteLine("Source: {0}", string.Join(", ", source.Reverse()));
Console.WriteLine("Destination: {0}", string.Join(", ", destination.Reverse()));
Console.WriteLine("Spare: {0}", string.Join(", ", spare.Reverse()));
Console.WriteLine();
}
示例15: StackToString
void StackToString(Stack<Type> buildStack)
{
this.BuildStack = buildStack.Reverse().ToArray();
this.buildStack = string.Empty;
foreach (var t in this.BuildStack)
this.buildStack += t.FullName + "\n";
}