• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Tree.Node类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Tree.Node的典型用法代码示例。如果您正苦于以下问题:C# Node类的具体用法?C# Node怎么用?C# Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Node类属于Tree命名空间,在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: print

        public override void print(Node t, int n, bool p)
        {
            if (!p)
            {
                var spaces = "";
                if (n >= 0) spaces = new string(' ', n);
                Console.Write(spaces + "(if ");
                if (t.getCdr().getCar().isPair())
                {
                    if((t.getCdr().getCar() as Cons).form is If ||
                        (t.getCdr().getCar() as Cons).form is Lambda ||
                        (t.getCdr().getCar() as Cons).form is Define)
                    t.getCdr().getCar().print(n+4, true);
                    else
                    {
                        t.getCdr().getCar().print(0, false);
                    }

                }
                else
                    t.getCdr().getCar().print(0, false);
                t = t.getCdr().getCdr();
                do
                {
                    Console.WriteLine("");
                    t.getCar().print(n + 4, false);
                    t = t.getCdr();
                } while (t.getCdr() != null);
                Console.WriteLine("");
                t.print(n, true);
            }
            else
            {
                var spaces = "";
                if (n >= 0) spaces = new string(' ', n);
                Console.Write("(if ");
                if (t.getCdr().getCar().isPair())
                {
                    if ((t.getCdr().getCar() as Cons).form is If ||
                        (t.getCdr().getCar() as Cons).form is Lambda ||
                        (t.getCdr().getCar() as Cons).form is Define)
                        t.getCdr().getCar().print(n+4, true);
                    else
                    {
                        t.getCdr().getCar().print(0, false);
                    }

                }
                t.getCdr().getCar().print(0, false);
                t = t.getCdr().getCdr();
                do
                {
                    Console.WriteLine("");
                    t.getCar().print(n + 4, false);
                    t = t.getCdr();
                } while (t.getCdr() != null);
                Console.WriteLine("");
                t.print(n, true);
            }
        }
开发者ID:tlecom3,项目名称:4101_prog1,代码行数:60,代码来源:If.cs


示例2: eval

 // REMEMBER: If not explictly false, then true.
 public Node eval(Node t, Environment e)
 {
     Node cond = t.getCdr().getCar(); // condition -> cadr(exp)
     if (cond == null)
     {
         Console.Error.WriteLine("Error: Null in Condition");
     }
     Node ifTrue = t.getCdr().getCdr().getCar(); // true -> caddr(exp)
     if (ifTrue == null)
     {
         Console.Error.WriteLine("Error: Null in True/If");
     }
     Node ifFalse = t.getCdr().getCdr().getCdr().getCar(); // false -> cadddr(exp)
     if (ifFalse == null)
     {
         Console.Error.WriteLine("Error: Null in False/Else");
     }
     bool checkTrueResult = checkTrue(t, e);
     if (checkTrueResult == true)
     {
         return ifTrue.eval(ifTrue, e);
     }
     else
     {
         return ifFalse.eval(ifFalse, e);
     }
 }
开发者ID:sbaldw2,项目名称:CSC4101,代码行数:28,代码来源:If.cs


示例3: print

 public override void print(Node t, int n, bool p)
 {
     // print leading spaces and '
     if (n < 0)
     {
         n = -(n + 1);
     }
     Console.Write(new string(' ', n) + "'");
     // if quote a list
     if (t.getCdr().getCar().isPair())
     {
         // this while is to print following quote as ' to get the sample output
         while (t.getCdr().getCar().getCar().isSymbol() 
             && ((Ident) t.getCdr().getCar().getCar()).getName().Equals("quote"))
         {
             Console.Write("'");
             t = t.getCdr().getCar();
         }
         // using the Regular form to print quoted list
         Special v = new Regular();
         v.print(t.getCdr().getCar(), 0, false);
         // if the caller asks for change line
         if (n > 0)
         {
             Console.WriteLine();
         }
     }
     // if quote a single element
     else
     {
         t.getCdr().getCar().print(0);
     }
 }
开发者ID:jktucn,项目名称:SchemePrettyPrinter,代码行数:33,代码来源:Quote.cs


示例4: eval

        public override Node eval(Node exp, Environment env)
        {
            int length = Util.expLength(exp);
            if (length < 3)
            {
                Console.Error.WriteLine("Error: invalid expression");
                return Nil.getInstance();
            }
            Node second = exp.getCdr().getCar();
            Node name, value;
            if (length == 3 && second.isSymbol())
            {
                name = second;
                value = exp.getCdr().getCdr().getCar().eval(env);
                env.define(name, value);
                return null;
            }
            if (!second.isPair())
            {
                Console.Error.WriteLine("Error: invalid expression");
                return Nil.getInstance();
            }
            name = second.getCar();
            Node lambda = exp.getCdr();
            lambda.setCar(second.getCdr());
            lambda = new Cons(new Ident("lambda"), lambda);
            value = lambda.eval(env);
            env.define(name, value);

            return null;
        }
开发者ID:jktucn,项目名称:SchemeInterpreter,代码行数:31,代码来源:Define.cs


示例5: print

        public override void print(Node t, int n, bool p)
        {
            Console.Write("".PadLeft(n));
               if ( p != true)
               {
               Console.Write("(");
               }
               if(t.getCar().isPair())
               {
               t.getCar().print(0);
               }
               else
               {
               t.getCar().print(0, true);
               }
               Console.Write(" ");

            if(t.getCdr() is Nil)
            {
                Console.WriteLine(")");
            }
            else
            {
                t.getCdr().print(0, true);
            }
            //  Console.WriteLine();
        }
开发者ID:CSC4101Projects,项目名称:Project1,代码行数:27,代码来源:Set.cs


示例6: eval

 public override Node eval(Node exp, Environment env)
 {
     int length = Util.expLength(exp);
     if (length < 3)
     {
         Console.Error.WriteLine("Error: invalid expression");
         return Nil.getInstance();
     }
     Node second = exp.getCdr().getCar();
     while (second.isPair())
     {
         if (Util.expLength(second.getCar()) != 2)
         {
             Console.Error.WriteLine("Error: invalid expression");
             return Nil.getInstance();
         }
         second = second.getCdr();
     }
     second = exp.getCdr().getCar();
     Environment env1 = new Environment(env);
     while (second.isPair())
     {
         Node id = second.getCar().getCar();
         Node val = second.getCar().getCdr().getCar();
         env1.define(id, val);
         second = second.getCdr();
     }
     Node exp1 = exp.getCdr().getCdr();
     return Begin.evalBody(exp1, env1);
 }
开发者ID:jktucn,项目名称:SchemeInterpreter,代码行数:30,代码来源:Let.cs


示例7: ConstuctTreeFromPreOrder

        /* A O(n) iterative program for construction of BST from preorder traversal */
        public Node ConstuctTreeFromPreOrder(int[] preOrder)
        {
            Node root = new Node();
            root.data = preOrder[0];
            Stack<Node> _stack = new Stack<Node>();
            Node temp;
            for (int i = 1; i < preOrder.Length; i++)
            {
                temp = null;
                while (_stack.Count > 0 && preOrder[i] > _stack.Peek().data)
                {
                    temp = _stack.Pop();
                }

                if (temp != null)
                {
                    temp.right.data = preOrder[i];
                    _stack.Push(temp.right);
                }
                else
                {
                    temp.left.data = preOrder[i];
                    _stack.Push(temp.left);
                }
            }
            return root;
        }
开发者ID:piyushkp,项目名称:DataStructure,代码行数:28,代码来源:tree.cs


示例8: ParseTree

        static Tree<int> ParseTree()
        {
            var nodes = new Dictionary<int, Node<int>>();
            Console.Write("Number of nodes:");
            int n = int.Parse(Console.ReadLine());
            Console.WriteLine("Start typing the node pairs separated by a single space");
            
            for (int i = 0; i < n-1; i++)
            {
                var pair = Console.ReadLine().Split();
                int first = int.Parse(pair[0]);
                int second = int.Parse(pair[1]);
                if (!nodes.ContainsKey(first))
                {
                    Node<int> parent = new Node<int>(first);
                    nodes.Add(first, parent);
                }

                if (!nodes.ContainsKey(second))
                {
                    Node<int> newNode = new Node<int>(second);
                    newNode.HasParent = true;
                    nodes.Add(second,newNode);
                    nodes[first].Children.Add(newNode);
                }

                nodes[first].Children.Add(nodes[second]);
                nodes[second].HasParent=true;

                
            }
            var root = nodes.First(x => x.Value.HasParent == false);
            var tree = new Tree<int>(root.Value);
            return tree;
        }
开发者ID:GenoGenov,项目名称:TelerikAcademyAssignments,代码行数:35,代码来源:Program.cs


示例9: apply

 // TODO: The method apply() should be defined in class Node
 // to report an error.  It should be overridden only in classes
 // BuiltIn and Closure.
 public override Node apply (Node args)
 {
     Node param = fun.getCdr().getCar();
     int numArgs = Util.expLength(args);
     int numParam = Util.expLength(param);
     if (numArgs != numParam)
     {
         Console.Error.WriteLine("Error: wrong number of arguments");
     }
     Environment env1 = new Environment(env);
     while (param.isPair() && args.isPair())
     {
         Node id = param.getCar();
         Node val = args.getCar();
         env1.define(id, val);
         param = param.getCdr();
         args = args.getCdr();
     }
     while (param.isPair())
     {
         Node id = param.getCar();
         Node val = Nil.getInstance();
         env1.define(id, val);
         param = param.getCdr();
     }
     Node exp1 = fun.getCdr().getCdr();
     return Begin.evalBody(exp1, env1);
 }
开发者ID:jktucn,项目名称:SchemeInterpreter,代码行数:31,代码来源:Closure.cs


示例10: print

        public override void print(Node t, int n, bool p)
        {
            // TODO: Implement this function.
            //  Console.Write("".PadLeft(n));
            if (!p)
            {
                Console.Write("".PadLeft(n) + '(');
            }
            t.getCar().print(0, !p);
            //  if(!t.getCdr().isNull())
            //  {
            //      Console.Write(" ");
            //  }
            if(t.getCdr().isNull())
            {
                t.getCdr().print(0, true);
                //  Console.WriteLine();
            }
            else {
                Console.Write(" ");
                t.getCdr().print(n, true);
            }

            //  if(t.getCdr().isNull())
            //  {
            //      Console.WriteLine();
            //  }
        }
开发者ID:CSC4101Projects,项目名称:Project1,代码行数:28,代码来源:Regular.cs


示例11: eval

 public override Node eval(Node t, Environment env)
 {
     if (t.getCdr() == Nil.getInstance())
     {
         Console.Error.WriteLine("Error: invalid argument");
         throw new InvalidOperationException();
     }
     if (t.getCdr().getCar().eval(env) != BoolLit.getInstance(false))
     {
         if (t.getCdr().getCdr() == Nil.getInstance())
         {
             Console.Error.WriteLine("Error: invalid argument");
             throw new InvalidOperationException();
         }
         return t.getCdr().getCdr().getCar().eval(env);
     }
     if (t.getCdr().getCdr() == Nil.getInstance())
     {
         Console.Error.WriteLine("Error: invalid argument");
         throw new InvalidOperationException();
     }
     if (t.getCdr().getCdr().getCdr() == Nil.getInstance())
     {
         return Nil.getInstance();
     }
     return t.getCdr().getCdr().getCdr().getCar().eval(env);
 }
开发者ID:Lumenze,项目名称:4101_prog2,代码行数:27,代码来源:If.cs


示例12: eval

 public override Node eval(Node t, Environment e)
 {
     if(t.getCdr() is Closure)
         return e.lookup(t.getCar()).apply(t.getCdr());
     else
     {
         Node args = t.getCdr();
         Node param;
         if (args.getCar().isSymbol())
             param = new Cons(e.lookup((Node)args.GetCar()), Nil.getInstance());
         else
             param = new Cons((Node)args.GetCar(), Nil.getInstance());
         Node currentNode = param;
         args = args.getCdr();
         while (args != Nil.getInstance())
         {
             if (args.getCar().isSymbol())
                 currentNode.setCdr(new Cons(e.lookup(args.getCar()), Nil.getInstance()));
             else
                 currentNode.setCdr(new Cons(args.getCar(), Nil.getInstance()));
             currentNode = currentNode.getCdr();
             args = args.getCdr();
         }
         return e.lookup(t.getCar()).apply(param);
     }
 }
开发者ID:Lumenze,项目名称:4101_prog2,代码行数:26,代码来源:Regular.cs


示例13: eval

 public override Node eval(Node t, Environment e)
 {
     while (t.getCdr() != Nil.getInstance())
     {
         t = t.getCdr();
         if (t.getCar().GetType() != typeof(Cons))
         {
             Console.Error.WriteLine("Error: invalid argument");
             throw new InvalidOperationException();
         }
         if (t.getCar().getCar().eval(e) == BoolLit.getInstance(true))
         {
             t = t.getCar();
             while(t.getCdr() != Nil.getInstance())
             {
                 t = t.getCdr();
                 if (t.getCdr() == Nil.getInstance()) break;
                 t.getCar().eval(e);
             }
             return (Node)t.getCar().eval(e);
         }
         else if (t.getCar().getCar().eval(e) != BoolLit.getInstance(false))
         {
             Console.Error.WriteLine("Error: invalid argument");
             throw new InvalidOperationException();
         }
     }
     return Nil.getInstance();
 }
开发者ID:Lumenze,项目名称:4101_prog2,代码行数:29,代码来源:Cond.cs


示例14: print

        public override void print(Node t, int n, bool p)
        {
            // TODO: Implement this function.
            Console.Write("".PadLeft(n));
            Console.Write("(define ");

            Node name = t.getCdr().getCar();
            name.print(n);

            Console.Write(" ");

            Node definition = t.getCdr().getCdr().getCar();
            if (definition.isNull())
            {
                Console.Error.Write("Syntax error with DEFINE-definition");
            }
            else if (definition.isPair())
            {
                Console.WriteLine();
                //  Console.Write("".PadLeft(n+4));
                definition.print(n+4);
            }
            else
            {
                definition.print(n);
            }
            // made n to 0
            //  Console.WriteLine();
            Console.WriteLine("".PadLeft(n) + ")");
        }
开发者ID:CSC4101Projects,项目名称:Project1,代码行数:30,代码来源:Define.cs


示例15: print

 public override void print(Node t, int n, bool p)
 {
     for (int i = Console.CursorLeft; i < n; i++)
         Console.Write(" ");
     if (!p)
     {
         Console.Write("(");
     }
     //print "let"
     t.getCar().print(n);
     Console.WriteLine();
     Node rest = t.getCdr();
     if (rest.isPair())
     {
         rest.getCar().print(n + 4, false);
         Console.WriteLine();
         while ((rest = rest.getCdr()) != Nil.getNil())
         {
             rest.getCar().print(n + 4, false);
             Console.WriteLine();
         }
         Console.Write(")");
     }
     else t.getCdr().print(n, true);
 }
开发者ID:matthewjwolff,项目名称:SchemePrettyPrinter,代码行数:25,代码来源:Let.cs


示例16: eval

 public override Node eval(Node t, Environment env)
 {
     Node clauseList = t.getCdr();
     Node clause = clauseList.getCar();
     while(clause != Nil.getInstance())
     {
         Node predicate = clause.getCar().eval(env);
         if(predicate == BoolLit.getInstance(true) || predicate.getName() == "else")
         {
             Node expressionList = clause.getCdr();
             //evaluate all expressions and return the result of the last evaluation
             Node lastEval = expressionList.getCar().eval(env);
             //If there are more expressions to evaluate
             while(expressionList.getCdr() != Nil.getInstance())
             {
                 expressionList = expressionList.getCdr();
                 lastEval = expressionList.getCar().eval(env);
             }
             return lastEval;
         }
         clauseList = clauseList.getCdr();
         clause = clauseList.getCar();
     }
     //Does not yet handle else's
     return Nil.getInstance();
 }
开发者ID:matthewjwolff,项目名称:Scheme4101,代码行数:26,代码来源:Cond.cs


示例17: evalLetBody

        public Node evalLetBody(Node t, Environment env)
        {
            if(t == Nil.getInstance()) //This isn't correct. What do?
            {
                Node l = new Cons(new Nil(), new Nil()); //tree with pair of ()
                return l;
            }
            else
            {
                Node restBody = t.getCdr();
                Node variable = t.getCar().getCar();
                Node value = t.getCar().getCdr().getCar();

                if(variable.isSymbol()) //was value earlier, should be variable?
                {
                    env.define(variable,value.eval(env));
                    return evalLetBody(restBody, env);
                }
                else if(!variable.isPair()) //if it is a cons node. ???
                {
                    Console.Write("Error in Let->evalLetBody, variable is not valid");
                    return new Nil();

                }
                else if(variable.isNull())
                {
                    return new Nil();
                }
                else
                {
                    return variable.eval(env);
                }
            }
        }
开发者ID:hcross2,项目名称:4330-Project-2,代码行数:34,代码来源:Let.cs


示例18: print

        public override void print(Node t, int n, bool p)
        {
            // TODO: Implement this function.
            Console.Write("".PadLeft(n));
            Console.WriteLine("(let");
            Node bindings = t.getCdr().getCar();

            if (bindings.isPair())
            {
                bindings.print(0,false);
            }
            else
            {
                Console.Error.WriteLine("Syntax error for LET-BINDINGS");
            }

            Console.Write("".PadLeft(n));
            Node body = t.getCdr().getCdr();

            if (body.isPair())
            {
                body.print(n+4, true);
            }
            else
            {
                Console.Error.WriteLine("Syntax error for LET-BODY");
            }
            Console.Write("".PadLeft(n)+ ")");
        }
开发者ID:CSC4101Projects,项目名称:Project1,代码行数:29,代码来源:Let.cs


示例19: assign

 public void assign(Node id, Node val)
 {
     // TODO: implement this function
        // create name
       //  if (search for name in either frame or environment)
        //     name = newvalue
 }
开发者ID:RanNPC,项目名称:Prog2,代码行数:7,代码来源:Environment.cs


示例20: print

        public override void print(Node t, int n, bool p)
        {
            for (int i = Console.CursorLeft; i < n; i++)
                Console.Write(" ");

            if (!p)
                Console.Write("(");
            //Print "lambda"
            t.getCar().print(n);
            Console.Write(" ");

            Node second = t.getCdr().getCar();
            if (second.isPair())
            {
                second.print(n, false);
            }
            Console.WriteLine();
            Node term = t.getCdr().getCdr();
            while(!term.isNull())
            {
                term.getCar().print(n + 4);
                term = term.getCdr();
                Console.WriteLine();
            }
            Nil.getNil().print(n,true);
        }
开发者ID:matthewjwolff,项目名称:SchemePrettyPrinter,代码行数:26,代码来源:Lambda.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tools.PointerEventInfo类代码示例发布时间:2022-05-26
下一篇:
C# Transitions.Transition类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap