本文整理汇总了C#中Stack.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.ToList方法的具体用法?C# Stack.ToList怎么用?C# Stack.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack.ToList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run(ref IGrid grid)
{
var startAt = grid.GetRandomCell;
active = new Stack<Cell>();
active.Push(startAt);
costs = new Dictionary<Cell, int>();
foreach(var cell in grid)
{
costs[cell] = GetRandomNumber(0, 100);
}
int iterations = 1;
while(active.Any())
{
iterations++;
var cell = Min(active); // Get the minimum value in the *active* set
var availableNeighbors = cell.Neighbors.Where(x => x.Links.Count == 0);
if (availableNeighbors.Any())
{
var neighbor = Min(availableNeighbors); // Get the minimum value in the *availableNeighbors* set
cell.Link(neighbor);
active.Push(neighbor);
}
else
{
var list = active.ToList();
list.Remove(cell);
active = new Stack<Cell>(list);
}
}
Console.WriteLine($"Iterations: {iterations}");
}
示例2: ShortestSequance
public static List<int> ShortestSequance(int start, int end)
{
Stack<int> sequance = new Stack<int>();
int currentNumber = end;
sequance.Push(currentNumber);
while (currentNumber > start)
{
if (currentNumber % 2 == 0 && currentNumber / 2 >= start)
{
currentNumber /= 2;
sequance.Push(currentNumber);
}
else if (currentNumber % 2 == 1 && currentNumber / 2 >= start)
{
currentNumber -= 1;
sequance.Push(currentNumber);
}
else if (currentNumber - 2 >= start)
{
currentNumber -= 2;
sequance.Push(currentNumber);
}
else if (currentNumber - 1 >= start)
{
currentNumber -= 1;
sequance.Push(currentNumber);
}
}
return sequance.ToList();
}
示例3: Run
public void Run(ref IGrid grid, SelectionFunction SelectionFunction)
{
var startAt = grid.GetRandomCell;
active = new Stack<Cell>();
active.Push(startAt);
while(active.Any())
{
var cell = SelectionFunction(active);
var availableNeighbors = cell.Neighbors.Where(x => x.Links.Count == 0);
if (availableNeighbors.Any())
{
var neighbor = availableNeighbors.Sample();
cell.Link(neighbor);
active.Push(neighbor);
}
else
{
var list = active.ToList();
list.Remove(cell);
active = new Stack<Cell>(list);
}
}
}
示例4: GetMaxHappiness
private static int GetMaxHappiness(Stack<string> atTable, List<string> free, Conditions conditions)
{
if (free.Count == 1)
{
atTable.Push(free.Single());
var table = new Table(atTable.ToList());
var totalHappiness = table.CalcTotalHappiness(conditions);
atTable.Pop();
return totalHappiness;
}
var maxHappiness = 0;
for (int i = 0; i < free.Count; i++)
{
atTable.Push(free[i]);
free.RemoveAt(i);
var happiness = GetMaxHappiness(atTable, free, conditions);
if (happiness > maxHappiness)
{
maxHappiness = happiness;
}
var person = atTable.Pop();
free.Insert(i, person);
}
return maxHappiness;
}
示例5: GetNextSteps
private void GetNextSteps(Stack<Node> currentChain, IEnumerable<Node> greyList, Node currentNode)
{
currentChain.Push(currentNode);
var newGreyList =
greyList
.Except(currentNode.Antecedents())
.Except(currentNode.Descendents())
.Distinct();
if (newGreyList.Count() == 0)
{
ConcurrencyChains.Add(currentChain.ToList());
MaxConcurrency = Math.Max(MaxConcurrency, (int) currentChain.Count);
}
foreach (var newPossible in newGreyList)
{
if (_previouslySeenRoots.Contains(newPossible)) continue;
GetNextSteps(currentChain, newGreyList, newPossible);
}
currentChain.Pop();
}
示例6: Run
public void Run(ref IGrid grid)
{
var startAt = grid.GetRandomCell;
Stack<Cell> active = new Stack<Cell>();
active.Push(startAt);
int iterations = 1;
while(active.Any())
{
iterations++;
var cell = active.Sample();
var availableNeighbors = cell.Neighbors.Where(x => x.Links.Count == 0);
if (availableNeighbors.Any())
{
var neighbor = availableNeighbors.Sample();
cell.Link(neighbor);
active.Push(neighbor);
}
else
{
var list = active.ToList();
list.Remove(cell);
active = new Stack<Cell>(list);
}
}
Console.WriteLine($"Iterations: {iterations}");
}
示例7: Execute
public static List<Dictionary<string, object>> Execute( this MySqlConnection connection, string sqlCmd, int start, int limit )
{
Stack<Dictionary<string, object>> output = new Stack<Dictionary<string, object>>();
MySqlDataReader reader = null;
try
{
MySqlCommand cmd = new MySqlCommand( sqlCmd, connection );
reader = cmd.ExecuteReader();
while( reader.Read() )
{
Dictionary<string, object> entry = new Dictionary<string, object>();
for( int i = 0; i < reader.FieldCount; i++ )
{
entry[ reader.GetDataTypeName( i ) ] = reader.GetValue( i );
}
output.Push( entry );
}
}
catch( MySqlException ex )
{
StaticLogger.Log( LogLevel.Error, "FAILED MySQL READ : " + ex.Message );
}
finally
{
if( reader != null )
reader.Close();
}
return output.ToList();
}
示例8: ReverseNumbers
private static IEnumerable<int> ReverseNumbers(IEnumerable<int> array)
{
var stack = new Stack<int>();
foreach (var element in array)
{
stack.Push(element);
}
return stack.ToList();
}
示例9: getSelector
private static string getSelector(Stack<HtmlNodeFacade> nodeHierarchy)
{
var lst = nodeHierarchy.ToList()
.Select(nd =>
{
string tagSelector = nd.tagName.ToLower() + nd.getAttribute("xmatch");
return tagSelector;
});
return string.Join(">", lst.Reverse().ToArray());
}
示例10: PathTo
public List<int> PathTo(int v)
{
var stack = new Stack<int>();
for (var w = v; w != s; w = edgeTo[w])
{
stack.Push(v);
}
stack.Push(s);
return stack.ToList();
}
示例11: LSP
public LSP(int idProyecto, int idLSP)
{
//Lee los datos de la tabla de LSP_Header
Data.dsTopologiaTableAdapters.LSPsTableAdapter HeaderAdapter = new Data.dsTopologiaTableAdapters.LSPsTableAdapter();
Data.dsTopologia.LSPsDataTable hdt = HeaderAdapter.SeleccionarListaLSPs(idProyecto, idLSP);
foreach(var dr in hdt)
{
this.idProyecto = dr.idProyecto;
this.idLSP = dr.idLSP;
if (!dr.IscNombreNull())
this.cNombre = dr.cNombre.Trim();
if (!dr.IsnBandwidthNull())
this.nBandwidth = dr.nBandwidth;
this.idRouterOrigen = dr.idRouterOrigen;
this.idRouterDestino = dr.idRouterDestino;
if (!dr.IsnSetupPriorityNull())
this.nSetupPriority = dr.nSetupPriority;
if (!dr.IsnHoldPriorityNull())
this.nHoldPriority = dr.nHoldPriority;
}
//Agrega router_origen al stack de nodos
Stack<Router> stackNodos = new Stack<Router>();
stackNodos.Push(new LER(this.idRouterOrigen, this.idProyecto));
//Bucle que agrega los routers de la lista de enlaces
Data.dsTopologiaTableAdapters.EnlacesLSPsTableAdapter DetailAdapter = new Data.dsTopologiaTableAdapters.EnlacesLSPsTableAdapter();
Data.dsTopologia.EnlacesLSPsDataTable ddt = DetailAdapter.SeleccionarListaEnlacesLSPs(idProyecto, idLSP);
foreach(var dr in ddt)
{
Enlace temp = new Enlace(dr.idLSP, dr.idProyecto);
Router lastNode = stackNodos.Peek();
//Agrega el router asociado al enlace que no esta en el tope del stack
if (lastNode.idRouter != temp.idRouterA)
stackNodos.Push(new LSR(temp.idRouterA, this.idProyecto));
else
stackNodos.Push(new LSR(temp.idRouterB, this.idProyecto));
}
//Finalmente, agrega router_destino al stack de nodos
stackNodos.Push(new LER(this.idRouterDestino, this.idProyecto));
//Convierte el stack a una lista
this.listaNodos = stackNodos.ToList();
//Populando los selectlists
this.listaNodosOrigen = LSP.ConvertDropdownNodosDisponibles(LSP.SelectListaNodosDisponibles(idProyecto, null, 0));
this.listaNextHop = new List<SelectListItem>();
}
示例12: ProcessWhereNode
private static bool ProcessWhereNode(XmlNode xmlNode, ref StringBuilder sb)
{
bool isSuccess = false;
Stack<string> operatorStack = new Stack<string>();
Queue<string> valueQueue = new Queue<string>();
string previousOp = string.Empty;
string strOperator = string.Empty;
try
{
//Call a method to iterate "recursively" throught the nodes to get the values and operators.
if (ProcessRecursiveWhereNode(xmlNode, "", "", ref operatorStack, ref valueQueue))
{
// For each operator adding parenthesis before starting
StringBuilder sbTmp = new StringBuilder();
operatorStack.ToList().ForEach(x => sbTmp.Append("("));
sb.Append(sbTmp.ToString());
while (valueQueue.Count > 0)
{
if (operatorStack.Count > 0)
{
strOperator = operatorStack.Pop();
}
else
{
strOperator = string.Empty;
}
sb.Append(valueQueue.Dequeue());
// After each logical operation closing parenthesis
if (previousOp != string.Empty)
sb.Append(")");
if (strOperator != string.Empty)
sb.Append(" " + strOperator + " ");
previousOp = strOperator;
}
}
isSuccess = true;
}
catch (Exception)
{
isSuccess = false;
}
return isSuccess;
}
示例13: CreateDirectory
public void CreateDirectory(string path)
{
var directory = _fileSystem.DirectoryInfo.FromDirectoryName(path);
if (!directory.Exists)
{
var nonExistingFolders = new Stack<DirectoryInfoBase>();
while (!directory.Exists)
{
nonExistingFolders.Push(directory);
directory = directory.Parent;
}
nonExistingFolders.ToList().ForEach(dir => dir.Create());
}
}
示例14: FindLast
private List<DataBlock> FindLast(DataBlock start)
{
var p = start;
var buffer = new Stack<DataBlock>();
while(p != _lastEol.Block)
{
buffer.Push(p);
if (p.PreviousBlock == null)
{
return buffer.ToList();
}
p = p.PreviousBlock;
}
buffer.Push(p);
return buffer.ToList();
}
示例15: SimplifyPath
public string SimplifyPath(string path) {
var stack = new Stack<string>();
var sb = new StringBuilder();
foreach (var ch in ((IEnumerable<char>)path).Concat(Enumerable.Repeat('/', 1)))
{
if (ch == '/')
{
if (sb.Length > 0)
{
var folder = sb.ToString();
sb.Clear();
switch (folder)
{
case ".":
break;
case "..":
if (stack.Any())
{
stack.Pop();
}
break;
default:
stack.Push(folder);
break;
}
}
}
else
{
sb.Append(ch);
}
}
if (stack.Count == 0)
{
sb.Append('/');
}
foreach (var folder in ((IEnumerable<string>)stack.ToList()).Reverse())
{
sb.Append('/');
sb.Append(folder);
}
return sb.ToString();
}