当前位置: 首页>>代码示例>>C#>>正文


C# Stack.ToList方法代码示例

本文整理汇总了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}");
        }
开发者ID:davidjeet,项目名称:MazesCSharp,代码行数:34,代码来源:TruePrim.cs

示例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();
        }
开发者ID:atanas-georgiev,项目名称:Data-Structures-and-Algorithms-Homeworks,代码行数:32,代码来源:Program.cs

示例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);
                }
            }
        }
开发者ID:davidjeet,项目名称:MazesCSharp,代码行数:25,代码来源:GrowingTree.cs

示例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;
 }
开发者ID:navoznov,项目名称:AdventOfCode,代码行数:25,代码来源:Program.cs

示例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();
        }
开发者ID:timbarrass,项目名称:Alembic.Tools,代码行数:26,代码来源:GraphConcurrencyCharacterisation.cs

示例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}");
        }
开发者ID:davidjeet,项目名称:MazesCSharp,代码行数:27,代码来源:SimplifiedPrim.cs

示例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();
        }
开发者ID:ghostmonk,项目名称:GhostmonkWeb,代码行数:32,代码来源:MySqlContainer.cs

示例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();
        }
开发者ID:Nikolay-D,项目名称:DataStructuresAndAlgorithms,代码行数:10,代码来源:Startup.cs

示例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());
 }
开发者ID:bahrus,项目名称:teaspoon,代码行数:10,代码来源:tspProcessor_Merge.cs

示例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();
 }
开发者ID:mvsusp,项目名称:Algorythms,代码行数:10,代码来源:Paths.cs

示例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>();
        }
开发者ID:diodax,项目名称:ProyectoMPLS,代码行数:52,代码来源:LSP.cs

示例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;
        }
开发者ID:Gravicode,项目名称:IDLAKE,代码行数:52,代码来源:CamlToSql.cs

示例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());
            }
        }
开发者ID:sietsevdschoot,项目名称:FolderDiff,代码行数:16,代码来源:FileSystemHelper.cs

示例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();
 }
开发者ID:JaegerJens,项目名称:FileIndexService,代码行数:16,代码来源:DataBlockRefinement.cs

示例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();
 }
开发者ID:alexguo88,项目名称:LeetCode,代码行数:44,代码来源:71.SimplifyPath.cs


注:本文中的Stack.ToList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。