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


C# Queue.dequeue方法代码示例

本文整理汇总了C#中Queue.dequeue方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.dequeue方法的具体用法?C# Queue.dequeue怎么用?C# Queue.dequeue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Queue的用法示例。


在下文中一共展示了Queue.dequeue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Transform

        public void Transform(string src, string dest)
        {
            Queue<string> q = new Queue<string>();
            q.enqueue(src);
            dict["src"] = true;// I visited this node.

            string temp= src;
            List<string> res = new List<string>();

            while (q.length!=0)
            {
                string word = q.dequeue();

                //if(word == dest) break;

                //create a new word and check into dictionary and add into queue
                for (int i = 0; i < word.Length; i++)
                {
                    for (int j = 0; i < 26; j++)
                    {
                        //creat a new word by replacing character at ith position
                        string newWord = word.Substring(0, i) + word[j] + word.Substring(i + 1); //w may be a dest

                        if (dict.ContainsKey(newWord) && dict["newWord"]==false)// newWord should not be visited, false means not visited before
                        {
                            q.enqueue(newWord);
                            res.Add(newWord);
                            temp = newWord;
                            break;
                        }
                    }
                    break;
                }
            }
        }
开发者ID:anuprao152,项目名称:GitHub-WebApp,代码行数:35,代码来源:WordLadder.cs

示例2: Main

        static void Main(string[] args)
        {
            Queue<int> list = new Queue<int>();
            Console.WriteLine(list.isEmpty());
            list.enqueue(0);
            list.enqueue(5);
            list.enqueue(7);
            list.enqueue(-4);
            list.enqueue(0);

            Console.WriteLine(list.dequeue());
            Console.WriteLine(list.dequeue());
            Console.WriteLine(list.dequeue());
            list.enqueue(9);
            Console.WriteLine(list.dequeue());
            Console.WriteLine(list.isEmpty());
            Console.WriteLine(list.isEmpty());
            list.nuke();
            Console.WriteLine(list.isEmpty());
            Console.ReadKey();
        }
开发者ID:Jobair96,项目名称:ADTs-Algorithms,代码行数:21,代码来源:Program.cs

示例3: SortByType

        public void SortByType()
        {
            //Bucket Sort
            /*
            A arry to be sorted
            n is length of A
            for i = 1 to n
            insert A[i] into B bucket (queue)
            for i = 0 to n-1
            sort B
            */

            //Generic Stack for each droid type
            Stack<Droid> protocolStack = new Stack<Droid>();
            Stack<Droid> utilityStack = new Stack<Droid>();
            Stack<Droid> janitorStack = new Stack<Droid>();
            Stack<Droid> astromechStack = new Stack<Droid>();

            //Create a Queue for Droids
            Queue<Droid> droidQueue = new Queue<Droid>();
            //Create a linked list for the droids
            LinkedList<Droid> droidLinkedList = new LinkedList<Droid>();

            int n = droidCollection.Length;

            //Move droid type into the bucket
            foreach (int i in droidCollection)
            {
                //check if value is not null
                if(droidCollection[i] != null)
                {
                    //Add a droid to the linked list
                    droidLinkedList.AddLast(droidCollection);
                }
                //Add a new node for the data in the linked list
                GenericNode<Droid> node = new GenericNode<Droid>();
                node.Next;
                droidQueue.enqueue(droidLinkedList);

            }

            //Push the droids into the queue(enqueue) and sort by pushing into their respected stacks

            foreach (int i in droidQueue)
            {
                switch (droidQueue.Equals)
                {
                    case "Protocol":
                        //take out of queue
                        //Add to the respected stack
                        protocolStack.push(droidQueue.dequeue());
                        break;
                    case "Utility":
                        utilityStack.push(droidQueue.dequeue());
                        break;
                    case "Janitor":
                        droidQueue.dequeue();
                        janitorStack.push(droidQueue.dequeue());
                        break;
                    case "Astromech":
                        droidQueue.dequeue();
                        astromechStack.push(droidQueue.dequeue());
                        break;
                }
            }
        }
开发者ID:YihanWang2015,项目名称:cis237assignment4,代码行数:66,代码来源:DroidCollection.cs


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