具有低间隔的重复低值的间隔树使用AVL树

问题描述

完成了针对间隔树的实现代码,该代码不允许重复的下限值。如果允许重复的值,则将进行所有更改。否则任何建议都将有助于解决该问题。


struct BST
{
  long long int key;
  int height;
  long long int max,high;
  struct BST *left,*right;
};


struct BST *newNode (long long int l,long long int r)
{
  struct BST *temp = (struct BST *) malloc (sizeof (struct BST));
  temp->key = l;
  temp->max = temp->high = r;
  temp->left = temp->right = NULL;
  temp->height = 0;
  return temp;
}

void Updatemax (struct BST *node)
{
  if (node)
    {
      node->max = node->high;
      if (node->left && node->left->max > node->high)
    node->max = node->left->max;
      if (node->right && node->right->max > node->max)
    node->max = node->right->max;
    }
}


bool AVL (struct BST *node)
{
  if (abs (Height (node->left) - Height (node->right)) < 2)
    return true;
  else
    return false;
}

void Inorder (struct BST *node)
{
  if (node)
    {
      Inorder (node->left);
      printf ("%lld: %lld %lld   ",node->key,node->high,node->max);
      Inorder (node->right);
    }
}

struct BST *Search (struct BST *node,long long int X)
{

  while (node)
    {
      if (X == node->key)
    return node;
      else if (X < node->key)
    node = node->left;
      else
    node = node->right;
    }
  return NULL;
}


struct BST *Overlap (struct BST *node,long long int l,long long int r)
{

  while (node)
    {
      if (l <= node->high && node->key <= r)
    return node;
      if (node->left && node->left->max >= l)
    node = node->left;
      else
    node = node->right;
    }
  return NULL;
}


struct BST *Insert (struct BST *node,long long int key,long long int r)
{
  // If the BST is empty,create a  new BST
  if (!node)
    return newNode (key,r);
  if (key < node->key)
    node->left = Insert (node->left,key,r);
  else if (key > node->key)
    node->right = Insert (node->right,r);
  node->height = Height (node);
  Updatemax (node);
  if (!AVL (node))
    {
      node = Rotate (node);
    }
  return node;
}

我需要为此修改哪些功能

  1. 应该为所有具有相同较低值的间隔将较高间隔的列表添加到单个节点,但这会增加线性搜索的时间。
  2. 在较高的值基础上打破平局,但这也会导致搜索/重叠查找操作的时间线性化。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)