⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsttest.java

📁 实现ADT,可以实现两个二叉树的几种逻辑关系来显示它们之间的联系.如:求两个二叉树是否是等价的.它们的交集并集是怎样的.等等.这样这些都是ADT要实现的方法.
💻 JAVA
字号:
import java.io.*;public class BSTTest {	        public static void main(String args[]) throws IOException {  	    BufferedReader stdin = new BufferedReader(    	                       new InputStreamReader(System.in));        BST intBST = new BST();        BST bst=new BST();        Comparable value;        while (true) {            System.out.println("-------------------------");            System.out.println("     1. 清空");                  System.out.println("     2. 插入");                System.out.println("     3. 删除");            System.out.println("     4. 检索");            System.out.println("     5. 检查是否是空");            System.out.println("     6. 节点数 ");            System.out.println("     7. 等价  " );            System.out.println("     8. 交集 ");///////            System.out.println("     9. 并集");/////////            System.out.println("     10.是否是子树");            System.out.println("     0. Exit");            System.out.print("\t选择菜单: ");            String s = stdin.readLine();            int choice = Integer.parseInt(s);            switch (choice) {                case 0 : System.out.println("结束.");	                System.exit(0);	            case 1 : System.out.println("已清空.");                    intBST.clear();                    break;                case 2 : System.out.print("输入一个整数: ");                    s = stdin.readLine();                    value = Integer.valueOf(s);                    intBST.insert(value);	                break;                case 3 : System.out.print("Enter an integer: ");                    s = stdin.readLine();                    value = Integer.valueOf(s);                    intBST.delete(value);                   System.out.println(value + " 已经删除.");	                break;                case 4 : System.out.print("输入一个整数: ");                    s = stdin.readLine();                    value = Integer.valueOf(s);                    if (intBST.contains(value))                        System.out.println("存在 " + value);                    else                        System.out.println("不存在" + value);	                break;	             case 5 :                     if(intBST.isEmpty())                     System.out.println("二叉树为空");                    else                     System.out.println("二叉树不是空的");                    break;                 case 6:                       System.out.println("二叉树有 "+intBST.size()+" 结点.");                     break;                case 7 :                     if(intBST.equals())                     System.out.println("the two bst are equal.");                     else                     System.out.println("the two bst are not equal.");                     break;                 case 8:                      intBST.intersection();                                           break;                 case 9:                      intBST.union();                      break;                 case 10:                      if(intBST.subset())                                            System.out.println("输入的二叉树是它的子树.");                      else                      System.out.println("输入的二叉树不是它的子树.");                                            break;                     default : System.out.println("错误的选项.");	                continue;            }            intBST.print();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -