Exemplo n.º 1
0
        private void UpdateOpenNodes(Context context)
        {
            NodeStack openNodes    = context._openNodes[guid];
            NodeStack tmpNodes     = context._tempNodes[guid];
            NodeStack oldOpenNodes = context._oldOpenNodes[guid];

            while (openNodes.Count > 0 /*&& oldOpenNodes.Count > 0*/)
            {
                if (openNodes.Count > oldOpenNodes.Count)
                {
                    tmpNodes.Push(openNodes.Pop());
                }
                else if (openNodes.Count < oldOpenNodes.Count)
                {
                    oldOpenNodes.Pop()._close(context);
                }
                else if (openNodes.Peek().guid != oldOpenNodes.Peek().guid)
                {
                    tmpNodes.Push(openNodes.Pop());
                    oldOpenNodes.Pop()._close(context);
                }
                else
                {
                    break;
                }
            }
            while (tmpNodes.Count > 0)
            {
                oldOpenNodes.Push(tmpNodes.Pop());
            }
        }
            public V Pop()
            {
                V val = stack.Pop();

                if (val.Equals(min))
                {
                    min = stack.Pop();
                }
                return(val);
            }
Exemplo n.º 3
0
 public override int Visit(ForInExpression forInExpression)
 {
     StartGraphNode(forInExpression);
     VisitChildren(forInExpression);
     NodeStack.Pop( );
     return(0);
 }
Exemplo n.º 4
0
 public override object?Visit(ConditionalExpression conditionalExpression)
 {
     StartGraphNode(conditionalExpression);
     VisitChildren(conditionalExpression);
     NodeStack.Pop( );
     return(null);
 }
Exemplo n.º 5
0
 public override object?Visit(ForInExpression forInExpression)
 {
     StartGraphNode(forInExpression);
     VisitChildren(forInExpression);
     NodeStack.Pop( );
     return(null);
 }
Exemplo n.º 6
0
 public override object?Visit(RootNode root)
 {
     StartGraphNode(root);
     VisitChildren(root);
     NodeStack.Pop( );
     return(null);
 }
Exemplo n.º 7
0
 public override object?Visit(Prototype prototype)
 {
     StartGraphNode(prototype);
     VisitChildren(prototype);
     NodeStack.Pop( );
     return(null);
 }
Exemplo n.º 8
0
        private static Node BuildTree(TokenList tokens)
        {
            var nodes = new NodeStack();

            while (tokens.Any() && !(tokens.Current.EndsExpressionOrParameters || tokens.Current.IsParameterSeparator || tokens.Current.EndsIndex))
            {
                if (tokens.Current.StartsExpressionOrParameters && nodes.LastAdded is MethodNode method)
                {
                    tokens.MoveNext();
                    ProcessParameters(tokens, method);
                }
                else if (tokens.Current.StartsExpressionOrParameters)
                {
                    tokens.MoveNext();
                    ProcessExpression(tokens, nodes);
                }
                else if (tokens.Current.StartsIndex)
                {
                    tokens.MoveNext();
                    ProcessIndex(tokens, nodes);
                }
                else
                {
                    nodes.Add(tokens.Current.CreateNode());
                }

                tokens.MoveNext();
            }
            return(nodes.Pop());
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var stack = new NodeStack <string>();

            stack.Push("Tom");
            stack.Push("Alice");
            stack.Push("Bob");
            stack.Push("Kate");

            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();
            string header = stack.Peek();

            Console.WriteLine($"Верхушка стека: {header}");
            Console.WriteLine();

            header = stack.Pop();
            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 10
0
 public override int Visit(Prototype prototype)
 {
     StartGraphNode(prototype);
     VisitChildren(prototype);
     NodeStack.Pop( );
     return(0);
 }
Exemplo n.º 11
0
 public override int Visit(RootNode root)
 {
     StartGraphNode(root);
     VisitChildren(root);
     NodeStack.Pop( );
     return(0);
 }
Exemplo n.º 12
0
        public void TestPopException()
        {
            NodeStack <string> stack    = new NodeStack <string>();
            string             actual   = stack.Pop();
            string             excerted = "Стек пуст";

            Assert.AreEqual(excerted, actual);
        }
Exemplo n.º 13
0
        public void TestPopElements()
        {
            NodeStack <string> stack = new NodeStack <string>();

            stack.Push("A");
            stack.Push("B");
            stack.Push("C");
            stack.Push("D");
            stack.Push("E");
            stack.Pop();
            stack.Pop();
            stack.Pop();
            string actual   = stack.Pop();
            string excerted = "B";

            Assert.AreEqual(excerted, actual);
        }
Exemplo n.º 14
0
 public override object?Visit(FunctionDefinition definition)
 {
     StartGraphNode(definition);
     ActiveNode.Label = $"{ActiveNode.Label}: {definition.Name}";
     VisitChildren(definition);
     NodeStack.Pop( );
     return(null);
 }
Exemplo n.º 15
0
        public override object?Visit(BinaryOperatorExpression binaryOperator)
        {
            StartGraphNode(binaryOperator);
            ActiveNode.Label = $"{ActiveNode.Label}: {binaryOperator.Name}";

            VisitChildren(binaryOperator);
            NodeStack.Pop( );
            return(null);
        }
Exemplo n.º 16
0
        public override object?Visit(FunctionCallExpression functionCall)
        {
            StartGraphNode(functionCall);
            ActiveNode.Label = $"{ActiveNode.Label}: {functionCall.FunctionPrototype.Name}";

            VisitChildren(functionCall);
            NodeStack.Pop( );
            return(null);
        }
Exemplo n.º 17
0
        public override object?Visit(ConstantExpression constant)
        {
            StartGraphNode(constant);
            ActiveNode.Label = $"{ActiveNode.Label}: {constant.Value}";

            VisitChildren(constant);
            NodeStack.Pop( );
            return(null);
        }
Exemplo n.º 18
0
        public override object?Visit(VariableReferenceExpression reference)
        {
            StartGraphNode(reference);
            ActiveNode.Label = $"{ActiveNode.Label}: {reference.Name}";

            VisitChildren(reference);
            NodeStack.Pop( );
            return(null);
        }
Exemplo n.º 19
0
        public override object?Visit(LocalVariableDeclaration localVariableDeclaration)
        {
            StartGraphNode(localVariableDeclaration);
            ActiveNode.Label = $"{ActiveNode.Label}: {localVariableDeclaration.Name}";

            VisitChildren(localVariableDeclaration);
            NodeStack.Pop( );
            return(null);
        }
Exemplo n.º 20
0
        public override object?Visit(ParameterDeclaration parameterDeclaration)
        {
            StartGraphNode(parameterDeclaration);
            ActiveNode.Label = $"{ActiveNode.Label}: {parameterDeclaration.Name}";

            VisitChildren(parameterDeclaration);
            NodeStack.Pop( );
            return(null);
        }
Exemplo n.º 21
0
        public void TestPushOneElement()
        {
            NodeStack <string> stack = new NodeStack <string>();

            stack.Push("Name");
            string actual   = stack.Pop();
            string excerted = "Name";

            Assert.AreEqual(excerted, actual);
        }
Exemplo n.º 22
0
        public void TestPopElements2()
        {
            NodeStack <string> stack = new NodeStack <string>();

            stack.Push("A");
            stack.Push("B");
            stack.Push("C");
            stack.Push("D");
            stack.Push("E");
            string actual1   = stack.Pop();
            string excerted1 = "E";

            Assert.AreEqual(excerted1, actual1);

            string actual2   = stack.Pop();
            string excerted2 = "D";

            Assert.AreEqual(excerted2, actual2);

            string actual3   = stack.Pop();
            string excerted3 = "C";

            Assert.AreEqual(excerted3, actual3);
        }
Exemplo n.º 23
0
        public string Dump(Context context)
        {
            System.Text.StringBuilder builder = new System.Text.StringBuilder();

            string[] statusColors = { "grey", "yellow", "green", "red" };

            NodeStack nodeStack = new NodeStack();

            nodeStack.Push(root);
            while (nodeStack.Count > 0)
            {
                BehaviourNode node    = nodeStack.Pop();
                int           depth   = 0;
                BehaviourNode tmpNode = node;
                while (tmpNode.parent != null)
                {
                    tmpNode = tmpNode.parent;
                    depth++;
                }
                while (depth-- > 0)
                {
                    builder.Append("    ");
                }
                RunningStatus lastRet = (RunningStatus)context.blackboard.GetInt(this.guid, node.guid, "Status");
                string        color   = statusColors[(int)lastRet];
                if (!context._travelNodes[this.guid].Contains(node))
                {
                    color = statusColors[0];
                }
                builder.Append(string.Format("<color={0}>{1}</color>\n", color, node.GetType().Name));
                if (node is Composite)
                {
                    var childrenList = (node as Composite)._getChildren();
                    for (int i = childrenList.Count - 1; i >= 0; --i)
                    {
                        nodeStack.Push(childrenList[i]);
                    }
                }
                else if (node is Decorator)
                {
                    nodeStack.Push((node as Decorator).GetChild());
                }
            }

            return(builder.ToString());
        }
Exemplo n.º 24
0
 public IEnumerable <int> PathTo(int v)
 {
     if (HasPathTo(v))
     {
         var path = new NodeStack <int>();
         for (int i = v; i != _s; i = _pathTo[i])
         {
             path.Push(i);
         }
         path.Push(_s);
         while (!path.IsEmpty())
         {
             yield return(path.Pop());
         }
     }
     ;
 }
Exemplo n.º 25
0
        public void Build()
        {
            if (_edges != null)
            {
                return;
            }

            _edges = new List <GraphEdge>();
            if (_nodes.Length == 0)
            {
                return;
            }

            SolverNode             bestSolverNode = null;
            SolverNode             root           = new SolverNode(_nodes);
            NodeStack <SolverNode> solverNodes    = new NodeStack <SolverNode>();

            solverNodes.Push(root);

            while (solverNodes.size > 0)
            {
                SolverNode currentSolverNode = solverNodes.Pop();
                if (currentSolverNode.IsComplete)
                {
                    if (bestSolverNode == null || bestSolverNode.CompareTo(currentSolverNode) > 0)
                    {
                        bestSolverNode = currentSolverNode;
                    }
                }
                else
                {
                    (SolverNode withEdge, SolverNode withoutEdge) = currentSolverNode.Split();
                    if (withEdge != null)
                    {
                        solverNodes.InsertIf(withEdge, (x) => { return(withEdge.CompareTo(x) <= 0); });
                    }
                    if (withoutEdge != null)
                    {
                        solverNodes.InsertIf(withoutEdge, (x) => { return(withoutEdge.CompareTo(x) <= 0); });
                    }
                }
            }

            _edges = bestSolverNode.Edges;
        }
Exemplo n.º 26
0
        static void Main(string[] args)
        {
            stack = new NodeStack <string>();

            stack.CollectionChanged += Stack_CollectionChanged;

            int    key = 1, answer;
            string value = "", peek, del;

            while (key != 0)
            {
                Console.Clear();
                Console.Write(
                    "           Menu:\n" +
                    "1: Add value to stack.\n" +
                    "2: Show all values from stack.\n" +
                    "3: Show top value of stack.\n" +
                    "4: Delete value from stack.\n" +
                    "0: Exit.\n" +
                    "Enter key: ");

                key = Convert.ToInt32(Console.ReadLine());

                switch (key)
                {
                //добавляем элементы в стек
                case 1:
                    Console.Write("\nHow many values do you want to insert?: ");
                    answer = Convert.ToInt32(Console.ReadLine());
                    for (int i = 0; i < answer; i++)
                    {
                        Console.Write("Add value: ");
                        value = Console.ReadLine();
                        stack.Push(value);

                        if (message != null)
                        {
                            Console.WriteLine($"\n{message}\n");
                        }
                    }
                    break;

                //выводим вместимое стека
                case 2:
                    try
                    {
                        stack.ReturnEmpty();
                        Console.WriteLine("\nStack values:\n");
                        foreach (var elem in stack)
                        {
                            Console.WriteLine(elem);
                        }
                        Console.WriteLine();
                    }
                    catch (InvalidOperationException err)
                    {
                        Console.WriteLine(err.Message);
                    }
                    break;

                case 3:
                    try
                    {
                        stack.ReturnEmpty();
                        peek = stack.Peek();
                        Console.WriteLine($"\nTop value in stack: {peek}\n");
                    }
                    catch (InvalidOperationException err)
                    {
                        Console.WriteLine(err.Message);
                    }
                    break;

                case 4:
                    try
                    {
                        stack.ReturnEmpty();
                        del = stack.Pop();
                        Console.WriteLine($"\nDeleted value is: {del}");

                        if (message != null)
                        {
                            Console.WriteLine($"\n{message}\n");
                        }
                    }
                    catch (InvalidOperationException err)
                    {
                        Console.WriteLine(err.Message);
                    }
                    break;

                case 0:
                    return;

                default:
                    Console.WriteLine("\nWrong input! Try again.\n");
                    break;
                }
                Console.Write("Press any key to continue...");
                Console.ReadKey();
            }
        }
Exemplo n.º 27
0
 private Node Pop( )
 {
     return(NodeStack.Pop( ));
 }
Exemplo n.º 28
0
 public void Pop()
 {
     NodeStack.Pop();
 }