免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
二叉排序數(shù)的實現(xiàn)
package net.oicp.shuangquan;
import java.io.*;
class Node{
 int data;
 Node lchild;
 Node rchild;
}
/*class Tree{
 
}*/
public class BinaryTree {
 /**
  * @param args
  */
 private Node root;
 public BinaryTree()
 {
  root=null;
 }
 public  void insert(int data)
 {
  Node tree=new Node();
  tree.data=data;
  //Node current=new Node();
  //current=tree;
  if(root==null)
  {
   root=tree;
   //current=root;
  }
  else
  {
   Node current,parent;
   current=root;
   while(true)
   {
    parent=current;
    if(data<current.data)
    {
     current=current.lchild;
     if(current==null)
     {
      parent.lchild=tree;
      return;
     }
     /*else
     {
      current=current.lchild;
     }*/
    }
    else
    {
     current=current.rchild;
     if(current==null)
     {
      parent.rchild=tree;
      return;
     }
    }
     
   }
   
  }
  
 }
 public Node find(int a)
 {
  Node current=root;
  while(a!=current.data)
  {
   current=a<current.data?current.lchild:current.rchild;
  }
  return current;
 }
 
 public static void main(String[] args) throws Exception
 {
  // TODO Auto-generated method stub
  BinaryTree tree=new BinaryTree();
  System.out.println("Please input the value: ");
  int j=Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
  while(j!=0)
  {
   tree.insert(j);
   j=Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
   
  }
  System.out.println("Please input the value what you want find: ");
  int i=Integer.parseInt(new BufferedReader(new InputStreamReader(System.in)).readLine());
  System.out.println(tree.find(i).data);
  
 }
}
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
數(shù)據(jù)結(jié)構(gòu)四:二叉樹(C++代碼)
二叉查找樹
紙上談兵: 樹, 二叉樹, 二叉搜索樹
二叉樹的遍歷;前序 中序 后序遍歷二叉樹;遞歸 非遞歸實現(xiàn); 重建二叉樹;編程之美重建二叉樹
二叉樹基本操作程序?qū)崿F(xiàn)
一篇不錯的紅黑樹代碼
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服