当前位置:编程学习 > C#/ASP.NET >>

C#算法实现二叉树,单链表,反向链表,stack栈

二叉查找树

// 二叉查找树节点 Binary search tree node

    public class BinarySearchTreeNode

    { public int key;// 二叉查找树节点的值

       public BinarySearchTreeNode left;// 二叉查找树节点的左子节点

       public BinarySearchTreeNode right;// 二叉查找树节点的右子节点

       /// 二叉查找树节点构造函数

       public BinarySearchTreeNode(int nodeValue)

       {   key = nodeValue;//nodeValue 节点的值

           left = null; right = null;

       }

       /// 插入节点

       public void InsertNode(BinarySearchTreeNode node)

       {   if(node.key > this.key)

           {  if(this.right == null)

              {   this.right = node;//node插入的节点

                  return;

              }

              else

                  this.right.InsertNode(node);

           }

           else

           {   if(this.left == null)

              {   this.left = node; return; }

              else

                  this.left.InsertNode(node);

           }

       }

       /// 二叉查找树查询

       public bool SearchKey(int searchValue)

       { if(this.key == searchValue)//searchValue需要查询的值

              return true;// 是否找到查询的值

           if(searchValue > this.key)

           {   if(this.right ==

补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,