【问题标题】:good ADT to implement BTREE实现 BTREE 的好 ADT
【发布时间】:2009-10-30 01:23:21
【问题描述】:

我应该使用什么数据结构来实现 BTree?为什么?

【问题讨论】:

  • BTree一种数据结构。所以这是一个奇怪的问题。你能说得更具体点吗?

标签: b-tree abstract-data-type


【解决方案1】:

您可以使用以下类创建一个 btree 节点。它有 7 个键和 8 个指针。你可以根据btree节点的定义改变它并对其进行操作

class BTNode
{
   BTNode pointers[];
   String keys[];
   int numKeys;
   boolean leaf;

   public BTNode()  // constructor to initialize values
   {
     leaf=true;
     numKeys=0;
     keys=new String[7];
     pointers=new BTNode[8];
   }
}

【讨论】:

    【解决方案2】:
    class Node {
       int data;
       Node left;
       Node right;
    }
    
    class BNode {
       Node[] nodes;
    }
    

    这样你将有指向 BNode 的每个节点的指针指向右子树和左子树....

    【讨论】:

      【解决方案3】:

      前几天我用LinkedList实现了BTree(删除O(1),插入O(1))。我会告诉你我的代码。这是我的 BNode 结构:

      public class BTree {
          private int order;
          private BNode root;
      
      
          public BTree(int order) {
              this.order = order;
          }
      
          public void insert(int value){}
          public boolean delete(int value){}
          public boolean contains(int value){}
          public void print(){}
      
      }
      
      class BNode{
          private LinkedList<Integer> values;
          private LinkedList<BNode> children;
      
          public BNode(){
              init(values);
              init(children); // every bnode with order k has k+1 children 
          }
      
      
      }
      

      【讨论】:

        猜你喜欢
        • 2011-05-29
        • 1970-01-01
        • 2011-07-25
        • 1970-01-01
        • 1970-01-01
        • 2011-02-04
        • 1970-01-01
        • 2017-10-28
        • 1970-01-01
        相关资源
        最近更新 更多