Peek() 공개 메소드

public Peek ( ) : Object
리턴 Object
        public IEnumerator Start()
        {
            pool = new InventoryPool<InventoryUIItemWrapper>(wrapperPrefab, 8);
            queue = new Queue<ItemHolder>(8);
            destroyTimer = new WaitForSeconds(slideAnimation.length - 0.025f);
            offsetTimer = new WaitForSeconds(offsetTimerSeconds);

            foreach (var inv in InventoryManager.GetLootToCollections())
            {
                inv.OnAddedItem += (items, amount, cameFromCollection) =>
                {
                    if (cameFromCollection == false)
                    {
                        queue.Enqueue(new ItemHolder() { item = items.FirstOrDefault(), stackSize = amount});
                    }
                };
            }

            while (true)
            {
                if (queue.Count > 0)
                {
                    ShowItem(queue.Peek().item, queue.Peek().stackSize);
                    queue.Dequeue(); // Remove it
                }

                yield return offsetTimer;
            }
        }
예제 #2
0
        public IEnumerator GenerateWorld()
        {
            bool flip = false;
            Queue<Node> current_node = new Queue<Node>();
            Queue<Node> tree = new Queue<Node>();
            current_node.Enqueue(root);
            tree.Enqueue(root);
            for(int i=0;i<depth;i++){
                for(int j=0;j<current_node.Count;j++){
                    flip = !flip;
                    current_node.Peek().Split(flip);

                    current_node.Enqueue(current_node.Peek().leafs[0]);
                    current_node.Enqueue(current_node.Peek().leafs[1]);
                    tree.Enqueue(current_node.Peek().leafs[0]);
                    tree.Enqueue(current_node.Peek().leafs[1]);
                    current_node.Dequeue();
                }
            }

            for(int i=0;i<tree.Count;i++){
                if(tree.Peek().initAutomata()){
                    progress+=1/tree.Count;
                    tree.Dequeue();
                }
            }
            yield return null;
        }
        private void QueueTest()
        {
            Queue queue = new Queue();
             queue.Enqueue( CAR_BANK[0] );
             queue.Enqueue( CAR_BANK[1] );
             queue.Enqueue( CAR_BANK[2] );

             ((Car)queue.Peek()).Display();
             DeQueued( (Car)queue.Dequeue() );

             ((Car)queue.Peek()).Display();
             DeQueued( (Car)queue.Dequeue() );

             ((Car)queue.Peek()).Display();
             DeQueued( (Car)queue.Dequeue() );

             try
             {
            ((Car)queue.Peek()).Display();
            DeQueued( (Car)queue.Dequeue() );
             }
             catch (Exception e)
             {
            Console.WriteLine( "Error!:{0}", e.Message );
             }
        }
예제 #4
0
        static void Main(string[] args)
        {
            // Stack - A LIFO collection

            Stack<string> stack = new Stack<string>();

            stack.Push("A");  // Push adds to the stack
            stack.Push("B");
            stack.Push("C");
            stack.Push("D");

            Console.WriteLine(stack.Peek()); // D - Peek returns the last added value without removing it

            Console.WriteLine(stack.Pop()); // D - Pop returna the last added value and removes it

            Console.WriteLine(stack.Peek());  // C

            // Queue - A FIFO collection

            Queue<string> queue = new Queue<string>();

            queue.Enqueue("a"); // Enqueue adds to the queue
            queue.Enqueue("b");
            queue.Enqueue("c");
            queue.Enqueue("d");

            Console.WriteLine(queue.Peek()); // a - Peek returns the beginning value without removing it

            Console.WriteLine(queue.Dequeue()); // a - Dequeue returns the beginning value and removes it

            Console.WriteLine(queue.Peek()); // b

            //--
            Console.ReadKey();
        }
예제 #5
0
        private void queueButton_Click(object sender, EventArgs e)
        {
            Queue fila = new Queue();

            //Adicionando itens
            fila.Enqueue("Gabriela");
            fila.Enqueue("Rafael");
            fila.Enqueue("Thiago");

            //Exibindo os itens da coleção
            foreach (string elemento in fila)
            {
                listBox1.Items.Add(elemento);
            }
            listBox1.Items.Add("--------------");

            //Exibindo o item primeiro da fila
            listBox1.Items.Add("primeiro da fila");
            listBox1.Items.Add(fila.Peek());
            listBox1.Items.Add("--------------");

            //Retirando um elemento da fila (primeiro da fila)
            fila.Dequeue();

            //Exibindo o item primeiro da fila
            listBox1.Items.Add("primeiro da fila");
            listBox1.Items.Add(fila.Peek());
        }
예제 #6
0
        //Main_7_9_6
        public static void Main_7_9_6()
        {
            Queue myQueue = new Queue();
            //��Queueβ�����Ԫ��
            myQueue.Enqueue("��");
            myQueue.Enqueue("��");
            myQueue.Enqueue("˭");

            //����Queueu��ʼ��Ԫ��
            Console.WriteLine(myQueue.Peek());
            //���ز��Ƴ�Queue��ʼ��Ԫ��
            myQueue.Dequeue();

            //����Queue
            foreach (object o in myQueue)
                Console.WriteLine(o.ToString());

            Stack myStack = new Stack();
            //��Stack��������Ԫ��
            myStack.Push("��");
            myStack.Push("��");
            myStack.Push("˭");

            //����Stack������Ԫ��
            Console.WriteLine(myStack.Peek());
            //���ز��Ƴ�Stack������Ԫ��
            myStack.Pop();

            //����Stack
            foreach (object o in myStack)
                Console.WriteLine(o.ToString());
        }
 public override bool Load(Queue<Token> tokens, Type tokenizerType,TemplateGroup group)
 {
     Token t = tokens.Dequeue();
     Match m;
     if (regAlternateFormat.IsMatch(t.Content))
     {
         m = regAlternateFormat.Match(t.Content);
         _variableName = m.Groups[1].Value;
         _entryName = m.Groups[2].Value;
         string tmp = t.Content.Substring(t.Content.IndexOf("|", m.Groups[2].Index) + 1);
         tmp = tmp.Substring(0, tmp.Length - 1);
         Tokenizer tok = (Tokenizer)tokenizerType.GetConstructor(new Type[] { typeof(string) }).Invoke(new object[] { tmp});
         _children = tok.TokenizeStream(group);
     }
     else
     {
         m = regVariableExtractor.Match(t.Content);
         _entryName = m.Groups[1].Value;
         _variableName = m.Groups[2].Value;
         if (regVarValueExtracor.IsMatch(_entryName))
             _entryName = regVarValueExtracor.Match(_entryName).Groups[2].Value;
         if (regListValueExtracor.IsMatch(_variableName))
             _variableName = regListValueExtracor.Match(_variableName).Groups[2].Value;
         while ((tokens.Count>0)&&!regEndFor.IsMatch(tokens.Peek().Content))
             _children.Add(ComponentExtractor.ExtractComponent(tokens, tokenizerType, group));
         if (tokens.Count > 0)
             tokens.Dequeue();
     }
     _entryName = _entryName.Trim();
     _variableName = _variableName.Trim();
     return true;
 }
예제 #8
0
        /// <summary>
        /// Evaluates all cacheItems associated with this cache item to determine if it
        /// should be considered expired. Evaluation stops as soon as any CacheItem is still valid.
        /// </summary>
        /// <returns>True if cache should be considered expired</returns>
        //public static bool HasExpired()
        //{
        //    foreach (KeyValuePair<string, CacheItem> keyValuePair in ItemDictionary)
        //    {
        //        if (keyValuePair.Value.expiryDate.CompareTo(DateTime.Now) > 0)
        //        {
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        /// <summary>
        /// 每隔1分钟将minutes分钟以前添加的元素扫描一次
        /// </summary>
        /// <param name="minutes"></param>
        private static void Scavange()
        {
            //Only scavange every 1 minute
            TimeSpan difference = DateTime.Now - _lastScavangeTime;

            if (difference.Minutes < IntervalMinutes)
            {
                return;
            }

            _lastScavangeTime = DateTime.Now;

            //NOTE: There is already a lock from Add method, which calls this method.

            //Monitor.Enter(keyQueue);
            int keyQueueCount = keyQueue.Count;

            //try
            //{
            for (int i = 0; i < keyQueueCount; i++)
            {
                if (ItemDictionary.ContainsKey((string)keyQueue.Peek()))
                {
                    if (ItemDictionary[(string)keyQueue.Peek()].timestamp.CompareTo(
                            DateTime.Now.AddMinutes(ScavangeMinutes * -1)) < 0)
                    {
                        CacheItem cahceItem = ItemDictionary[(string)keyQueue.Peek()];
                        _Remove((string)keyQueue.Dequeue());
                        cahceItem.Dispose();
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    keyQueue.Dequeue();
                }
            }
            //}
            //finally
            //{
            //    //Monitor.Exit(keyQueue);
            //}
            GCWrapper.Collect();
        }
예제 #9
0
        public static int GetMinDiceThrows(int[] board, int board_size)
        {
            bool[] visited = new bool[board_size];

            for (int i = 0; i < board_size; i++)
            {
                visited[i] = false;
            }

            visited[0] = true;
            Queue que = new Queue();
            SnakeNLadder queEntry = new SnakeNLadder(0, 0);
            que.Enqueue(queEntry);

            SnakeNLadder item = (SnakeNLadder)que.Peek();
            while (que.Count > 0)
            {
                item = (SnakeNLadder) que.Peek();
                int vertex = item.v;

                //Ending condition:  We're at the last piece;
                if (vertex == board_size - 1)
                {
                    break;
                }

                que.Dequeue();
                /* 1 ~ 6 dice here, also cannot exceed board size for obvious reason
                */
                for (int j = vertex +1; j <= (vertex + 6) && j < board_size; j++)
                {
                    if (!visited[j])
                    {
                        SnakeNLadder entry = new SnakeNLadder(j, item.dist + 1);
                        visited[j] = true;

                        //if we ru n into a ladder or snake here...
                        if (board[j] != -1)
                        {
                            entry.v = board[j];
                        }
                        que.Enqueue(entry);
                    }
                }
            }
            return item.dist;
        }
        private void ExecuteAlgorithm(int x, int y, IsValidHandler isValid, PointActionHandler action)
        {
            ///Flood-Fill algorithm
            Queue<Point> q = new Queue<Point>();

            if (regionMask[x, y])
                return;

            q.Enqueue(new Point(x, y));

            while (q.Count > 0)
            {
                Point p = q.Peek();
                int x1 = p.X;
                int y1 = p.Y;

                if (isValid.Invoke(p))
                {
                    action.Invoke(p.X, p.Y);
                }

                if (isValid.Invoke(new Point(x1, y1 + 1)))
                {
                    action.Invoke(x1, y1 + 1);
                    q.Enqueue(new Point(x1, y1 + 1));
                }

                if (isValid.Invoke(new Point(x1, y1 - 1)))
                {
                    action.Invoke(x1, y1 - 1);
                    q.Enqueue(new Point(x1, y1 - 1));
                }

                if (isValid.Invoke(new Point(x1 + 1, y1)))
                {
                    action.Invoke(x1 + 1, y1);
                    q.Enqueue(new Point(x1 + 1, y1));
                }

                if (isValid.Invoke(new Point(x1 - 1, y1)))
                {
                    action.Invoke(x1 - 1, y1);
                    q.Enqueue(new Point(x1 - 1, y1));
                }

                q.Dequeue();

                if (border)
                {
                    q.Clear();
                    depth = Int32.MaxValue;
                }
            }
            ///end of Flood-Fill algorithm
        }
예제 #11
0
        private static void doBFS(int[][] matrix, int x, int y)
        {
            Queue q = new Queue();
            int tmp;
            int xx, yy;
            int i;
            int dist;

            q.Enqueue(x * m + y);
            while (q.Count>0) {
                tmp = (int)q.Peek();
                q.Dequeue();
                x = tmp / m;
                y = tmp % m;
                dist = matrix[x][y] > 0 ? matrix[x][y] : 0;
                for (i = 0; i < 4; ++i) {
                    // one of 4 neighbors -
                    xx = x + dd[i,0];
                    yy = y + dd[i,1];
                    // boundary check - avoid duplication calculations as well
                    // the order is also important; in the array; and then,
                    // check node is not room;
                    // and then, node is already with less steps
                    //
                if (
                    // node is out of boundary of matrix
                    !inBound(xx, yy) ||       // node is not room - secondary check
                    matrix[xx][yy] < 0 ||     // node visited has less steps to a guard
                    (matrix[xx][yy] > 0 && matrix[xx][yy] <= dist + 1)) {
                    // out of boundary
                    // a guard or a blockade
                    // the distance is no shorter
                    continue;
                } // if the node on the queue is the Guard node, (value: -1)

                bool queuedNodeIsGuard = (dist == 0); //
                bool queueNodeIsRoom = (dist >= 1);
                if (queuedNodeIsGuard)
                    matrix[xx][yy] = 1;
                // else if the node on the queue is a room, need to compare the distance
                else if (queueNodeIsRoom )
                {
                    // keep minimum value
                    bool neverCalculated = matrix[xx][yy] == 0;
                    bool hasHighSteps = matrix[xx][yy] > dist + 1;
                    bool needUpdate = (neverCalculated || hasHighSteps);

                    if(needUpdate)
                        matrix[xx][yy] = dist+1;
                    }

                    q.Enqueue(xx * m + yy);
                }
            }
        }
예제 #12
0
        public void runQueue()
        {
            // Create a queue
            // Using Queue class
            System.Collections.Queue my_queue = new System.Collections.Queue();

            // Adding elements in Queue
            // Using Enqueue() method
            my_queue.Enqueue("GFG");
            my_queue.Enqueue("Geeks");
            my_queue.Enqueue("GeeksforGeeks");
            my_queue.Enqueue("geeks");
            my_queue.Enqueue("Geeks123");

            Console.WriteLine("Total elements present in my_queue: {0}",
                              my_queue.Count);

            // Checking if the element is
            // present in the Queue or not
            if (my_queue.Contains("GeeksforGeeks") == true)
            {
                Console.WriteLine("Element available...!!");
            }
            else
            {
                Console.WriteLine("Element not available...!!");
            }

            // Obtain the topmost element of my_queue
            // Using Dequeue method
            Console.WriteLine("Topmost element of my_queue"
                              + " is: {0}", my_queue.Dequeue());


            Console.WriteLine("Total elements present in my_queue: {0}",
                              my_queue.Count);

            // Obtain the topmost element of my_queue
            // Using Peek method
            Console.WriteLine("Topmost element of my_queue is: {0}",
                              my_queue.Peek());
            // After Dequeue method
            Console.WriteLine("Total elements present in my_queue: {0}",
                              my_queue.Count);

            // Remove all the elements from the queue
            my_queue.Clear();

            // After Clear method
            Console.WriteLine("Total elements present in my_queue: {0}",
                              my_queue.Count);

            Console.ReadLine();
        }
예제 #13
0
        public void PeekShouldPeekSourceQueue()
        {
            // arrange
            var source = new Queue<object>();
            var target = new QueueAdapter<object>( source );

            // act
            target.Enqueue( new object() );

            // assert
            Assert.Equal( source.Peek(), target.Peek() );
        }
예제 #14
0
 private object PeekData(IOutputPort op, object selector)
 {
     if (m_queue.Count > 0)
     {
         object data = m_queue.Peek();
         return(data);
     }
     else
     {
         return(null);
     }
 }
예제 #15
0
        public void MostrarCola(ListBox lista, Queue cola, Label turno)
        {
            lista.Items.Clear();
            //Mostrar los valores
            foreach (Persona item in cola)
                lista.Items.Add(item);

            if (cola.Count > 0)
                turno.Text = String.Format("Turno: {0}", cola.Peek());
            else
                turno.Text = "Sin elementos";
        }
예제 #16
0
        public static void Main(string[] args)
        {
            System.Collections.Queue kö = new System.Collections.Queue(10);
            {
                kö.Enqueue(1);
                kö.Enqueue(2);
                kö.Enqueue(3);
                kö.Enqueue(15);
                kö.Enqueue(null);
                kö.Enqueue(20);
                kö.Enqueue("test string");
                kö.Enqueue(25);


                Console.WriteLine($"Totalt antal element = {kö.Count}"); //Räknar antal element i kön

                Console.WriteLine(kö.Peek());                            //Kollar elementen i kön enligt ordning
                kö.Dequeue();
                Console.WriteLine(kö.Peek());
                kö.Dequeue();
                Console.WriteLine(kö.Peek());
                kö.Dequeue();
                kö.Dequeue();
                Console.WriteLine(kö.Peek());
                kö.Dequeue();
                kö.Dequeue();
                Console.WriteLine(kö.Peek());
                kö.Dequeue();
                Console.WriteLine(kö.Peek());

                Console.WriteLine($"Antal element efter = {kö.Count}"); // Visar att elementen tagits bort

                kö.Clear();
            }
        }
예제 #17
0
 static public int Peek(IntPtr l)
 {
     try {
         System.Collections.Queue self = (System.Collections.Queue)checkSelf(l);
         var ret = self.Peek();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
예제 #18
0
 public void MostrarCola(ListBox lista,Queue Cola, Label turno)
 {
     //Limpiando los valores
     lista.Items.Clear();
     //Mostrando los valores
     foreach (Persona item in Cola)
         lista.Items.Add(item);//Si agregas un . despues de item .Nombre solo aparece el nombre en el listbox
     if (Cola.Count > 0)
     {
         turno.Text = String.Format("Turno: {0}", Cola.Peek());
     }
     else
         turno.Text = "Sin elementos";
 }
예제 #19
0
 void Start()
 {
     _instrument = transform.parent.GetComponentInChildren<Instrument>();
     char[] splitters = { '\n' };
     string[] allStringTimings = trackFile.text.Split(splitters);
     _noteTimings = new Queue();
     foreach(string s in allStringTimings) {
         if(!string.IsNullOrEmpty(s)) {
             _noteTimings.Enqueue((float) Convert.ToInt32(s));
         }
     }
     _startTime = Time.time;
     Debug.Log(_noteTimings.Peek());
 }
예제 #20
0
        public void MostrarCola(ListBox lista, Queue cola, Label turno)
        {
            // Limpiando Valores
            lista.Items.Clear();
            // Mostrando los valores
            foreach (Persona item in cola)
                lista.Items.Add(item);

            if (cola.Count > 0)
            {
                turno.Text = String.Format("Turno: {0}", cola.Peek()); // peek es para saber cual es el ultimo de la cola
            }
            else turno.Text = "Sin elementos";
        }
        private void ExecuteAlgorithm(int x, int y, IsValidHandler isValid, PointActionHandler action)
        {
            ///Flood-Fill algorithm
            Queue<Point> q = new Queue<Point>();

            if (regionMask[x, y] != 0)
                return;

            q.Enqueue(new Point(x, y));

            while (q.Count > 0)
            {
                Point p = q.Peek();
                int x1 = p.X;
                int y1 = p.Y;

                if (isValid.Invoke(p) & !trainset.Contains(image.GetPixel(x1, y1)))
                {
                    action.Invoke(p.X, p.Y);
                }

                if (isValid.Invoke(new Point(x1, y1 + 1)))
                {
                    action.Invoke(x1, y1 + 1);
                    q.Enqueue(new Point(x1, y1 + 1));
                }

                if (isValid.Invoke(new Point(x1, y1 - 1)))
                {
                    action.Invoke(x1, y1 - 1);
                    q.Enqueue(new Point(x1, y1 - 1));
                }

                if (isValid.Invoke(new Point(x1 + 1, y1)))
                {
                    action.Invoke(x1 + 1, y1);
                    q.Enqueue(new Point(x1 + 1, y1));
                }

                if (isValid.Invoke(new Point(x1 - 1, y1)))
                {
                    action.Invoke(x1 - 1, y1);
                    q.Enqueue(new Point(x1 - 1, y1));
                }

                q.Dequeue();
            }
            ///end of Flood-Fill algorithm
        }
예제 #22
0
 static int Peek(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         System.Collections.Queue obj = (System.Collections.Queue)ToLua.CheckObject(L, 1, typeof(System.Collections.Queue));
         object o = obj.Peek();
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #23
0
        public void DequeueShouldDequeueSourceQueue()
        {
            // arrange
            var source = new Queue<object>();
            var target = new QueueAdapter<object>( source );

            target.Enqueue( new object() );

            var expected = source.Peek();

            // act
            var actual = target.Dequeue();

            // assert
            Assert.Equal( expected, actual );
        }
        /*
           Latest update: July 23, 2015
         * Leetcode question: Binary tree level order traversal
         *
         * 1. Practice more using Interface instead of actual class, like ArrayList in function return
         * 2. Change the return using IList<IList<int>>
         * 3. Test the code using leetcode online judge
         * Read the website about ArrayList vs List:
         * https://social.msdn.microsoft.com/Forums/vstudio/en-US/37c64e16-69e9-4935-abaa-ee8987230240/arraylist-vs-ilistobject?forum=netfxbcl&prof=required
         *   julia now understands the importance to use the interface, more generic, and less type casting,
         *   quick running time.
         *
         *   Leetcode online result:
         *   34 / 34 test cases passed.
             Status: Accepted
             Runtime: 536 ms
         */
        public static IList<IList<int>> levelOrder(TreeNode root)
        {
            IList<IList<int>> result = new List<IList<int>>();

            if (root == null)
                return (IList<IList<int>>)result;

            List<int> level = new List<int>();

            Queue<TreeNode> toVisit = new Queue<TreeNode>();

            toVisit.Enqueue(root);
            toVisit.Enqueue(null);

            while (true)
            {
                TreeNode cur = toVisit.Peek();
                toVisit.Dequeue();
                // end a level

                if (cur == null)
                {
                    List<int> list = new List<int>(); // julia: bug fix
                    list.AddRange(level);  // julia: bug fix
                    result.Add(list);

                    if (toVisit.Count == 0)
                        break;

                    // add a new End-Of-Level
                    level.Clear();

                    toVisit.Enqueue(null);
                }
                else
                {
                    level.Add(cur.val);
                    if (cur.left != null)
                        toVisit.Enqueue(cur.left);
                    if (cur.right != null)
                        toVisit.Enqueue(cur.right);
                }
            }

            return (IList<IList<int>>)result;
        }
예제 #25
0
        static void Main(string[] args)
        {
            //Array:
            int[] array1 = { 3, 4, 33, 4, 5, 112, 1, 12, 1, 21, 2, 12, 43, 54, 215, 3, 5, 2, 46, 57 };
            displayArray(array1);
            Console.WriteLine();

            //Queue:
            Queue first = new Queue();
            first.Enqueue(7);
            first.Enqueue(722);
            first.Enqueue(45);
            first.Enqueue(16);
            Console.WriteLine("Que value: {0}", first.Count);
            first.Dequeue();
            Console.WriteLine("Que value after a dequeue: {0}", (int) first.Peek());

            //Halts console window:
            Console.ReadKey();
        }
예제 #26
0
        public override bool Handle(object input, Queue<string> tokens)
        {
            var elementType = _property.PropertyType.GetGenericArguments().First();
            var list = typeof (List<>).CloseAndBuildAs<IList>(elementType);

            var wasHandled = false;
            while (tokens.Count > 0 && !tokens.Peek().StartsWith(InputParser.FLAG_PREFIX))
            {
                var value = _converter.FromString(tokens.Dequeue(), elementType);
                list.Add(value);

                wasHandled = true;
            }

            if (wasHandled)
            {
                _property.SetValue(input, list, null);
            }

            return wasHandled;
        }
예제 #27
0
파일: Form1.cs 프로젝트: tca85/ASP.NET
        private void btnFila_Click(object sender, EventArgs e)
        {
            Queue fila = new Queue();

            //adicionando itens
            fila.Enqueue("1º elemento");
            fila.Enqueue("2º elemento");
            fila.Enqueue("3º elemento");

            //exibindo os itens da COLEÇÃO
            listBox1.Items.Add("Primeiro a entrar, primeiro a sair - FIFO ");
            foreach (string elemento in fila)
            {
                listBox1.Items.Add(elemento);
            }

            //retirar elemento da fila
            //fila.Dequeue();

            //topo da fila
            listBox1.Items.Add("Topo da pilha: " + fila.Peek());
        }
예제 #28
0
            public override void execute3(RunTimeValueBase thisObj,FunctionDefine functionDefine,SLOT returnSlot,SourceToken token,StackFrame stackframe,out bool success)
            {
                System.Collections.Queue queue =
                    (System.Collections.Queue)((LinkObj <object>)((ASBinCode.rtData.rtObjectBase)thisObj).value).value;

                try
                {
                    object obj = queue.Peek();

                    stackframe.player.linktypemapper.storeLinkObject_ToSlot(obj,functionDefine.signature.returnType,returnSlot,bin,stackframe.player);
                    //returnSlot.setValue((int)array.GetValue(index));
                    success = true;
                }
                catch (RuntimeLinkTypeMapper.TypeLinkClassException tlc)
                {
                    success = false;
                    stackframe.throwAneException(token,tlc.Message);
                }
                catch (KeyNotFoundException)
                {
                    success = false;
                    stackframe.throwAneException(token,"Queue内的值没有链接到脚本");
                }
                catch (ArgumentException a)
                {
                    success = false;
                    stackframe.throwAneException(token,a.Message);
                }
                catch (IndexOutOfRangeException i)
                {
                    success = false;
                    stackframe.throwAneException(token,i.Message);
                }
                catch (InvalidOperationException io)
                {
                    success = false;
                    stackframe.throwAneException(token,io.Message);
                }
            }
예제 #29
0
파일: OPZ.cs 프로젝트: Denakol/PerlMt
        private void AEM(Stack<string> stack, Queue<string> queueResult, Queue<string> queue)
        {
            int i=2;
            while (queue.Peek() != "R8")
            {

                string temp;
                temp = queue.Dequeue();
                if (isIdeficatinoOrConst(temp))
                {
                    queueResult.Enqueue(temp);
                    continue;
                }
                if (temp == "R4") // )
                {
                    popBrackets(stack, queueResult);
                    continue;
                }
                if (temp == "R1")
                {
                    while (stack.Peek() != "AEM")
                    {
                        queueResult.Enqueue(stack.Pop());
                    }
                    i++;
                    continue;
                }
                WorkForPrioritet(queueResult, stack, temp);

            }
            queue.Dequeue();
            while (stack.Peek() != "AEM")
            {
                queueResult.Enqueue(stack.Pop());
            }
            stack.Pop();
            queueResult.Enqueue(String.Format("{0}{1}", i, "AEM"));
        }
예제 #30
0
        private void queueButton_Click(object sender, EventArgs e)
        {
            Queue fila = new Queue();

            //Adicionando itens
            fila.Enqueue("banana");
            fila.Enqueue("laranja");
            fila.Enqueue("maça");
            fila.Enqueue("uva");

            //Exibindo os itens da coleção
            foreach (string item in fila)
            {
                exemploListBox.Items.Add(item);
            }
            exemploListBox.Items.Add("--------------------------------");

            //Exibindo o primeiro item da fila
            exemploListBox.Items.Add("Primeiro item da fila: " + fila.Peek().ToString());

            exemploListBox.Items.Add("--------------------------------");

            //Removendo um item da fila
            fila.Dequeue();

            //Exibindo os itens da coleção
            foreach (string item in fila)
            {
                exemploListBox.Items.Add(item);
            }
            exemploListBox.Items.Add("--------------------------------");

            //Exibindo o primeiro item da fila após o Dequeue
            exemploListBox.Items.Add("Primeiro item da fila após o Dequeue: " + fila.Peek().ToString());

            exemploListBox.Items.Add("--------------------------------");
        }
예제 #31
0
        public void GenericStack()
        {
            Stack<Product> stack = new Stack<Product>();
            stack.Push(new Product(001, "mouse stack", 12));
            stack.Push(new Product(002, "cookies", 20));
            Console.WriteLine("\npeek: " + stack.Peek());

            Queue<Product> q = new Queue<Product>();
            q.Enqueue(new Product(001, "mouse q", 12));
            q.Enqueue(new Product(002, "coffee", 4.78));
            Console.WriteLine(q.Peek());

            SortedSet<Product> ss = new SortedSet<Product>(new Product());
            ss.Add(new Product(001, "mouse", 19.78));
            ss.Add(new Product(002, "hello", 200));
            ss.Add(new Product(004, "cup", 4.6));
            ss.Add(new Product(003, "cake", 1.56));
            ss.Add(new Product(005, "tv", 120));
            Console.WriteLine("\nsorted set");
            foreach (Product item in ss)
            {
                Console.WriteLine(item);
            }
        }
예제 #32
0
        private static bool ParseOptions(string progdir, string[] args, out Options options)
        {
            options = new Options();
            bool endnamed = false;
            string optname = null;
            bool help = false;
            Queue<string> unnamed = new Queue<string>();

            for (int i = 0; i < args.Length; i++)
            {
                string optarg = null;

                if (args[i].StartsWith("--"))
                {
                    optname = args[i].Substring(2);
                }
                else if (args[i].StartsWith("-") || args[i].StartsWith("/"))
                {
                    optname = args[i].Substring(1);
                }
                else
                {
                    optarg = args[i];
                }

                if (optname == "")
                {
                    endnamed = true;
                }

                if (!endnamed && optname != null)
                {
                    if (optname.Contains(":"))
                    {
                        optarg = optname.Substring(optname.IndexOf(":") + 1);
                        optname = optname.Substring(0, optname.IndexOf(":")).ToLower();
                    }
                    if (optname != null &&
                        optname.Length >= 1 &&
                        ("template".StartsWith(optname) ||
                         "datasource".StartsWith(optname) ||
                         "savedir".StartsWith(optname) ||
                         "record".StartsWith(optname)))
                    {

                        if (optarg == null && i + 1 < args.Length)
                        {
                            i++;
                            optarg = args[i];
                        }

                        if ("template".StartsWith(optname))
                        {
                            optname = "template";
                        }
                        else if ("datasource".StartsWith(optname))
                        {
                            optname = "datasource";
                        }
                        else if ("savedir".StartsWith(optname))
                        {
                            optname = "savedir";
                        }
                        else if ("record".StartsWith(optname))
                        {
                            optname = "record";
                        }
                    }

                    switch (optname)
                    {
                        case "pdf":
                            options.ExportPdf = true;
                            optname = null;
                            break;
                        case "no-pdf":
                            options.ExportPdf = false;
                            optname = null;
                            break;
                        case "pub":
                            options.ExportPub = true;
                            optname = null;
                            break;
                        case "no-pub":
                            options.ExportPub = false;
                            optname = null;
                            break;
                        case "wingdings":
                            options.UseWingdingTicks = true;
                            optname = null;
                            break;
                        case "no-wingdings":
                            options.UseWingdingTicks = false;
                            optname = null;
                            break;
                        case "template":
                            try
                            {
                                options.TemplateName = Path.GetFullPath(optarg);
                            }
                            catch
                            {
                                options.TemplateName = optarg;
                            }

                            optname = null;
                            break;
                        case "datasource":
                            try
                            {
                                options.DataSourceName = Path.GetFullPath(optarg);
                            }
                            catch
                            {
                                options.DataSourceName = optarg;
                            }

                            optname = null;
                            break;
                        case "savedir":
                            options.SaveDir = Path.GetFullPath(optarg);
                            optname = null;
                            break;
                        case "record":
                            options.Names.Add(optarg);
                            break;
                        case "help":
                            help = true;
                            break;
                        case "?":
                            goto case "help";
                        default:
                            goto case "help";
                    }
                }
                else
                {
                    unnamed.Enqueue(optarg);
                }
            }

            if (options.TemplateName == null && unnamed.Count != 0)
            {
                string name = unnamed.Peek();
                if (name.ToLower().EndsWith(".pub"))
                {
                    name = unnamed.Dequeue();
                }
                else if (name.ToLower().EndsWith(".xls") ||
                         name.ToLower().EndsWith(".xlsx") ||
                         name.ToLower().EndsWith(".xlsb") ||
                         name.ToLower().EndsWith(".xlsm"))
                {
                    options.DataSourceName = unnamed.Dequeue();
                    name = options.DataSourceName.Substring(0, options.DataSourceName.LastIndexOf('.')) + ".pub";
                }
                else
                {
                    name = null;
                    help = true;
                }

                try
                {
                    if (name != null)
                    {
                        options.TemplateName = Path.GetFullPath(name);
                    }
                }
                catch
                {
                    options.TemplateName = name;
                }
            }

            if (unnamed.Count != 0)
            {
                options.Names.AddRange(unnamed);
                unnamed.Clear();
            }

            if (String.IsNullOrEmpty(options.SaveDir))
            {
                if (options.TemplateName != null)
                {
                    options.SaveDir = Path.GetDirectoryName(Path.GetFullPath(options.TemplateName));
                }
                else
                {
                    options.SaveDir = progdir;
                }
            }

            return !help;
        }
 public void PeekingIntoAQueue()
 {
     Queue<string> queue = new Queue<string>();
     queue.Enqueue("one");
     Assert.Equal("one", queue.Peek());
     queue.Enqueue("two");
     Assert.Equal("one", queue.Peek());
 }
        public static string 分割指示記号を取り除く(string text)
        {
            {
                text = Regex.Replace(text, @"(?<!\\)[()]", "");
                text = Regex.Replace(text, @"\\([()])", "$1");
            }
            var queue = new Queue<char>(text.ToCharArray());
            var sb = new StringBuilder();

            while (0 < queue.Count())
            {
                var current = queue.Dequeue();
                if (IsSpecialCharsA(current))
                {
                    sb.Append(current);
                }
                else if ('/' == current)
                {
                }
                else if (' ' == current)
                {
                    sb.Append(current);
                }
                else if ('+' == current)
                {
                    if (!IsSpecialCharsA(queue.Peek()))
                    {
                        sb.Append(' ');
                    }
                }
                else
                {
                    sb.Append(current);
                }
            }
            return sb.ToString();
        }
        public static IEnumerable<MondaiWord> Split2(string s)
        {
            if (string.IsNullOrWhiteSpace(s)) throw new ArgumentException();
            s = 括弧内の単語をプラス記号で繋ぐ(s);
            var queue = new Queue<char>(s.ToCharArray());
            var sb = new StringBuilder();
            var left = false;
            var right = false;

            while (0 < queue.Count())
            {
                var current = queue.Dequeue(); // 下部にもDequeue()あり

                // 特殊文字Bの場合
                if (IsSpecialCharsB(current) && 0 == sb.Length && '+' != queue.Peek())
                {
                    sb.Append(current);
                    yield return new MondaiWord(sb.ToString(), left, right);
                    sb.Length = 0;
                    left = false;
                    right = false;
                }
                // 特殊文字Aの場合
                else if (IsSpecialCharsA(current))
                {
                    if (0 != sb.Length)
                    {
                        yield return new MondaiWord(sb.ToString(), left, right);
                        sb.Length = 0;
                        left = false;
                        right = false;
                    }
                    sb.Append(current);
                }
                else if ('/' == current)
                {
                    right = true;
                    if (0 == sb.Length) throw new ArgumentException();
                    yield return new MondaiWord(sb.ToString(), left, right);
                    sb.Length = 0;
                    left = true;
                    right = false;
                }
                else if (' ' == current)
                {
                    if (0 == sb.Length) throw new ArgumentException();
                    yield return new MondaiWord(sb.ToString(), left, right);
                    sb.Length = 0;
                    left = false;
                    right = false;
                }
                else if ('+' == current)
                {
                    // 空白と置換する'+', 置換しない'*'を用意するべき。というかそもそもダブルクォーテーションはSpecialCharsに入れるべきではない。
                    // 以下は応急処置

                    if (!IsSpecialCharsA(queue.Peek()))
                    {
                        if (!(0 < sb.Length && IsSpecialCharsB(sb[sb.Length - 1])))
                        {
                            sb.Append(' ');
                        }
                    }
                    else
                    {
                        sb.Append(queue.Dequeue());
                    }
                }
                else
                {
                    sb.Append(current);
                }
            }
            if (0 != sb.Length)
            {
                yield return new MondaiWord(sb.ToString(), left, right);
            }
        }
예제 #36
0
 public void PeekingIntoAQueue()
 {
     // Peek allows you to see which element Dequeue would return, but without removing it.
     Queue<string> queue = new Queue<string>();
     queue.Enqueue("one");
     queue.Enqueue("two");
     Assert.Equal(FILL_ME_IN, queue.Peek());
 }
예제 #37
0
파일: Program.cs 프로젝트: CS302/Group16
        static void Main(string[] args)
        {
            // {()} --> правильный
            // {(})[<]> --> неправильный

            /*
             * Пользовательское меню.
             * Выберите файл: ..., ....
             * 1-2
             *
             * 1 файл: Ввод данных: ФИО, №рейса, №билета, А/П вылета, А/П прилета
             *
             * 2 файл: №билета, идентификатор чемодана
             *
             * команда - "закончить"
             *
             * Вы вводите программе: номер билета
             * Программа выдает всю инф-ию о пасажире:
             * ФИО, №рейса, А/П вылета,
             * А/П прилета,
             * идентификатор чемодана
             */

            string path = Path.Combine("", "", "");

            //ShowList();
            //ShowListGeneric();

            //ShowStack();

            Queue<int> queue = new Queue<int>();
            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(5);

            foreach (int item in queue)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine("***************");

            Console.WriteLine(queue.Peek());
            Console.WriteLine(queue.Peek());

            Console.WriteLine(queue.Dequeue());
            Console.WriteLine(queue.Dequeue());
            Console.WriteLine(queue.Dequeue());
            Console.WriteLine(queue.Dequeue());
            Console.WriteLine(queue.Dequeue());
            //int number = stack.Peek();
            //Console.WriteLine(number);
            //
            //number = stack.Pop();
            //Console.WriteLine(number);
            //
            //number = stack.Peek();
            //Console.WriteLine(number);

            /*ArrayList list = new ArrayList();
            list.Add(new Driver("John", 27, 6435, "BMW", 256));
            list.Add(new Manager("Hulk", 25, 465138, 25));
            list.Add(new Manager("Helena", 25, 478656, 12));
            list.Add(new Driver("Jason", 45, 46513, "BMW", 256));
            list.Add(new Manager("Mary", 27, 461577, 15));

            foreach (object item in list)
            {
                (item as Worker).Print();
            }

            Console.WriteLine(list.Count);
            list.RemoveAt(3);
            Console.WriteLine(list.Count);

            (list[3] as Worker).Print();

            list.Add("Rabotnik");
            foreach (object item in list)
            {
                (item as Worker).Print();
            }*/
        }
예제 #38
0
    /// <summary>
    /// 添加到已完成功能提示列表
    /// </summary>
    /// <param name="funcId"></param>
    private void CompleteNewFuncOpen(GuideDefine.FuncOpenShowData showData)
    {
        if (null == showData)
        {
            return;
        }
        if (showData.FOT == GuideDefine.FuncOpenType.Base)
        {
            //1、从当前新功能开启列表中移除
            if (null != m_lst_canDoFuncOpen && m_lst_canDoFuncOpen.Contains(showData.FuncOpenId))
            {
                m_lst_canDoFuncOpen.Remove(showData.FuncOpenId);
            }

            bool add = false;
            //2、并添加到已完成提醒功能列表
            if (null != m_lst_alreadyDoFuncOpen && !m_lst_alreadyDoFuncOpen.Contains(showData.FuncOpenId))
            {
                m_lst_alreadyDoFuncOpen.Add(showData.FuncOpenId);
                add = true;
            }

            GuideDefine.LocalFuncOpenData openData = null;
            if (TryGetFuncOpenData(showData.FuncOpenId, out openData))
            {
                if (openData.NeedSort)
                {
                    List <uint> sortIds       = null;
                    bool        needRefreshUI = false;
                    if (!m_dic_completeFuncSort.TryGetValue(openData.SortGroup, out sortIds))
                    {
                        sortIds = new List <uint>();
                        sortIds.Add(showData.FuncOpenId);
                        m_dic_completeFuncSort.Add(openData.SortGroup, sortIds);
                        needRefreshUI = true;
                    }
                    else if (!sortIds.Contains(showData.FuncOpenId))
                    {
                        sortIds.Add(showData.FuncOpenId);
                        sortIds.Sort((left, right) =>
                        {
                            GuideDefine.LocalFuncOpenData leftData  = null;
                            GuideDefine.LocalFuncOpenData rightData = null;
                            if (TryGetFuncOpenData(left, out leftData) && TryGetFuncOpenData(right, out rightData))
                            {
                                return(leftData.SortID - rightData.SortID);
                            }
                            return(0);
                        });
                        needRefreshUI = true;
                    }
                    if (needRefreshUI)
                    {
                        DoRefreshNewFuncOpenStaus(openData.SortGroup);
                    }
                }
                else if (null != openData.CreateFuncObj && !openData.CreateFuncObj.activeSelf)
                {
                    openData.CreateFuncObj.SetActive(true);
                }
            }

            if (add)
            {
                Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.UIEVENTNEWFUNCOPEN, showData.FuncOpenId);
                //发送已完成消息
                SendNewFuncOpenComplete(showData.FuncOpenId);
            }
        }
        else if (showData.FOT == GuideDefine.FuncOpenType.Skill)
        {
            if (null != m_FuncCommonNoticesQ && m_FuncCommonNoticesQ.Count != 0)
            {
                GuideDefine.FuncOpenShowData cacheShowData = (GuideDefine.FuncOpenShowData)m_FuncCommonNoticesQ.Peek();
                if (cacheShowData.FuncOpenId == showData.FuncOpenId)
                {
                    //取出第一个
                    m_FuncCommonNoticesQ.Dequeue();
                }
            }
        }
        m_currentFuncOpenShowData = null;
        Engine.Utility.EventEngine.Instance().DispatchEvent((int)Client.GameEventID.UIEVENTNEWFUNCCOMPLETE, showData);
    }