本文整理汇总了C#中System.Collections.Stack.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.ToList方法的具体用法?C# Stack.ToList怎么用?C# Stack.ToList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Stack
的用法示例。
在下文中一共展示了Stack.ToList方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToTitle
public string ConvertToTitle(int n)
{
Stack<char> s = new Stack<char> ();
while (n > 0)
{
n--;
int remainder = n % 26;
s.Push ((char)(65 + remainder));
n = (int) n / 26;
}
return string.Join("",s.ToList());
}
示例2: PathTo
public List<int> PathTo(int s)
{
if (!HasPathTo(s)) {
return null;
}
Stack<int> stack = new Stack<int> ();
stack.Push (s);
int temp = s;
while (v != edgeTo[temp]) {
stack.Push (edgeTo[temp]);
temp = edgeTo [temp];
}
stack.Push (v);
return stack.ToList();
}
示例3: SetChildren
private void SetChildren(QueryNode parent)
{
var args = new Stack<QueryNode>();
// remove all nodes from expression until we find the parent
while (this.filterExpression.Peek() != parent)
{
args.Push(this.filterExpression.Pop());
}
parent.SetChildren(args.ToList());
}
示例4: TreeLevelOrderPrintBottomUp
public void TreeLevelOrderPrintBottomUp(TreeNode root)
{
Queue<TreeNode> q = new Queue<TreeNode>();
Stack<string> stack = new Stack<string> ();
string tmp = "";
int curCount = 1;
int nextCount = 0;
if (root == null) {
return;
}
q.Enqueue (root);
while (q.Count > 0) {
var cur = q.Dequeue ();
curCount -= 1;
tmp += cur.val + " ";
var left = cur.left;
var right = cur.right;
if (left != null) {
q.Enqueue (left);
nextCount += 1;
}
if (right != null) {
q.Enqueue (right);
nextCount += 1;
}
if (curCount == 0) {
stack.Push (tmp.TrimEnd(' '));
tmp = "";
curCount = nextCount;
nextCount = 0;
}
}
foreach (var item in stack.ToList()) {
Console.WriteLine (item);
}
}
示例5: GetEdgesBranching
/// <summary>
/// Получение текущих ребер для данного ветвления
/// </summary>
/// <param name="branch">ветвление</param>
/// <returns>список ребер ветлений</returns>
public List<Digraph.Edge> GetEdgesBranching(Branch branch)
{
var stack = new Stack<Digraph.Edge>();
var current = branch;
while (current.Parent != null)
{
stack.Push(current.BranchingEdge);
current = current.Parent;
}
return stack.ToList();
}
示例6: findPath
// hunts for a patch and stores it in arraylist of routes.
private void findPath(String origin, String dest, GraphNode<String> graphnode, GraphNode<String>previous, ref Stack<String> stak, ref ArrayList routes)
{
// one true condition
if (graphnode.Value.ToLower().Equals(dest.ToLower()))
{
String[] path = stak.ToArray<String>();
Array.Reverse(path);
routes.Add(path);
return;
}
// only can do this stuff if the current node is not the root node
if (previous != null)
{
// check if its a cyclic graph back to the origin
if (graphnode.Value.ToLower().Equals(origin.ToLower()))
{
return;
}
// check if the current node only has on vertex back to its parent
if ((graphnode.Neighbors.Count == 1) && (graphnode.Neighbors[0].Value.ToLower().Equals(previous.Value.ToLower())))
{
return;
}
// deal with cyclic nodes by using history to detect.
// remove newly added node and root node in temp list
// for detection
List<String> temp = stak.ToList<String>();
temp.RemoveAt(0);
temp.RemoveAt((temp.Count - 1));
if (temp.Contains(graphnode.Value))
{
return;
}
}
// checks to see if node has no connections to any other nodes
if ((graphnode.Neighbors.Count == 0) && (!graphnode.Value.ToLower().Equals(dest.ToLower())))
{
return;
}
foreach (GraphNode<String> node in graphnode.Neighbors)
{
// push stack to maintain history
stak.Push(node.Value);
if ((previous == null) || (!node.Value.ToLower().Equals(previous.Value.ToLower())))
{
findPath(origin, dest, node, graphnode, ref stak, ref routes);
}
stak.Pop();
}
return;
}