亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? avl_tree.h

?? AVL Tree的實現
?? H
?? 第 1 頁 / 共 2 頁
字號:
		  return(null());
		set_gt(old_h, get_lt(bal_h, false));
		set_lt(deep_h, get_gt(bal_h, false));
		set_lt(bal_h, old_h);
		set_gt(bal_h, deep_h);

		int bf = get_bf(bal_h);
		if (bf != 0)
		  {
		    if (bf > 0)
		      {
			set_bf(old_h, -1);
			set_bf(deep_h, 0);
		      }
		    else
		      {
			set_bf(deep_h, 1);
			set_bf(old_h, 0);
		      }
		    set_bf(bal_h, 0);
		  }
		else
		  {
		    set_bf(old_h, 0);
		    set_bf(deep_h, 0);
		  }
	      }
	    else
	      {
		set_gt(bal_h, get_lt(deep_h, false));
		set_lt(deep_h, bal_h);
		if (get_bf(deep_h) == 0)
		  {
		    set_bf(deep_h, -1);
		    set_bf(bal_h, 1);
		  }
		else
		  {
		    set_bf(deep_h, 0);
		    set_bf(bal_h, 0);
		  }
		bal_h = deep_h;
	      }
	  }
	else
	  {
	    // "Less than" subtree is deeper.

	    deep_h = get_lt(bal_h);
	    if (read_error())
	      return(null());

	    if (get_bf(deep_h) > 0)
	      {
		handle old_h = bal_h;
		bal_h = get_gt(deep_h);
		if (read_error())
		  return(null());
		set_lt(old_h, get_gt(bal_h, false));
		set_gt(deep_h, get_lt(bal_h, false));
		set_gt(bal_h, old_h);
		set_lt(bal_h, deep_h);

		int bf = get_bf(bal_h);
		if (bf != 0)
		  {
		    if (bf < 0)
		      {
			set_bf(old_h, 1);
			set_bf(deep_h, 0);
		      }
		    else
		      {
			set_bf(deep_h, -1);
			set_bf(old_h, 0);
		      }
		    set_bf(bal_h, 0);
		  }
		else
		  {
		    set_bf(old_h, 0);
		    set_bf(deep_h, 0);
		  }
	      }
	    else
	      {
		set_lt(bal_h, get_gt(deep_h, false));
		set_gt(deep_h, bal_h);
		if (get_bf(deep_h) == 0)
		  {
		    set_bf(deep_h, 1);
		    set_bf(bal_h, -1);
		  }
		else
		  {
		    set_bf(deep_h, 0);
		    set_bf(bal_h, 0);
		  }
		bal_h = deep_h;
	      }
	  }

	return(bal_h);
      }

  };

template <class abstractor, unsigned max_depth, class bset>
inline base_avl_tree<abstractor, max_depth, bset>::handle
  base_avl_tree<abstractor, max_depth, bset>::insert(handle h)
  {
    set_lt(h, null());
    set_gt(h, null());
    set_bf(h, 0);

    if (root == null())
      root = h;
    else
      {
	// Last unbalanced node encountered in search for insertion point.
	handle unbal = null();
	// Parent of last unbalanced node.
	handle parent_unbal = null();
	// Balance factor of last unbalanced node.
	int unbal_bf;

	// Zero-based depth in tree.
	unsigned depth = 0, unbal_depth = 0;

	// Records a path into the tree.  If branch[n] is true, indicates
	// take greater branch from the nth node in the path, otherwise
	// take the less branch.  branch[0] gives branch from root, and
	// so on.
	bset branch;

	handle hh = root;
	handle parent = null();
	int cmp;

	while (hh != null())
 	  {
	    if (get_bf(hh) != 0)
	      {
		unbal = hh;
		parent_unbal = parent;
		unbal_depth = depth;
	      }
	    cmp = cmp_n_n(h, hh);
	    if (cmp == 0)
	      // Duplicate key.
	      return(hh);
	    parent = hh;
	    hh = cmp < 0 ? get_lt(hh) : get_gt(hh);
	    if (read_error())
	      return(null());
	    branch[depth++] = cmp > 0;
	  }

	//  Add node to insert as leaf of tree.
	if (cmp < 0)
	  set_lt(parent, h);
	else
	  set_gt(parent, h);

	depth = unbal_depth;

	if (unbal == null())
	  hh = root;
	else
	  {
	    cmp = branch[depth++] ? 1 : -1;
	    unbal_bf = get_bf(unbal);
	    if (cmp < 0)
	      unbal_bf--;
	    else  // cmp > 0
	      unbal_bf++;
	    hh = cmp < 0 ? get_lt(unbal) : get_gt(unbal);
	    if (read_error())
	      return(null());
	    if ((unbal_bf != -2) && (unbal_bf != 2))
	      {
		// No rebalancing of tree is necessary.
		set_bf(unbal, unbal_bf);
		unbal = null();
	      }
	  }

	if (hh != null())
	  while (h != hh)
	    {
	      cmp = branch[depth++] ? 1 : -1;
	      if (cmp < 0)
		{
		  set_bf(hh, -1);
		  hh = get_lt(hh);
		}
	      else // cmp > 0
		{
		  set_bf(hh, 1);
		  hh = get_gt(hh);
		}
	      if (read_error())
		return(null());
	    }

	if (unbal != null())
	  {
	    unbal = balance(unbal);
	    if (read_error())
	      return(null());
	    if (parent_unbal == null())
	      root = unbal;
	    else
	      {
		depth = unbal_depth - 1;
		cmp = branch[depth] ? 1 : -1;
		if (cmp < 0)
		  set_lt(parent_unbal, unbal);
		else  // cmp > 0
		  set_gt(parent_unbal, unbal);
	      }
	  }

      }

    return(h);
  }

template <class abstractor, unsigned max_depth, class bset>
inline base_avl_tree<abstractor, max_depth, bset>::handle
  base_avl_tree<abstractor, max_depth, bset>::search(key k, search_type st)
  {
    const int MASK_HIGH_BIT = (int) ~ ((~ (unsigned) 0) >> 1);

    int cmp, target_cmp;
    handle match_h = null();
    handle h = root;

    if (st & LESS)
      target_cmp = 1;
    else if (st & GREATER)
      target_cmp = -1;
    else
      target_cmp = 0;

    while (h != null())
      {
	cmp = cmp_k_n(k, h);
	if (cmp == 0)
	  {
	    if (st & EQUAL)
	      {
		match_h = h;
		break;
	      }
	    cmp = -target_cmp;
	  }
	else if (target_cmp != 0)
	  if (!((cmp ^ target_cmp) & MASK_HIGH_BIT))
	    // cmp and target_cmp are both positive or both negative.
	    match_h = h;
	h = cmp < 0 ? get_lt(h) : get_gt(h);
	if (read_error())
	  {
	    match_h = null();
	    break;
	  }
      }

    return(match_h);
  }

template <class abstractor, unsigned max_depth, class bset>
inline base_avl_tree<abstractor, max_depth, bset>::handle
  base_avl_tree<abstractor, max_depth, bset>::search_least(void)
  {
    handle h = root, parent = null();

    while (h != null())
      {
	parent = h;
	h = get_lt(h);
	if (read_error())
	  {
	    parent = null();
	    break;
	  }
      }

    return(parent);
  }

template <class abstractor, unsigned max_depth, class bset>
inline base_avl_tree<abstractor, max_depth, bset>::handle
  base_avl_tree<abstractor, max_depth, bset>::search_greatest(void)
  {
    handle h = root, parent = null();

    while (h != null())
      {
	parent = h;
	h = get_gt(h);
	if (read_error())
	  {
	    parent = null();
	    break;
	  }
      }

    return(parent);
  }

template <class abstractor, unsigned max_depth, class bset>
inline base_avl_tree<abstractor, max_depth, bset>::handle
  base_avl_tree<abstractor, max_depth, bset>::remove(key k)
  {
    // Zero-based depth in tree.
    unsigned depth = 0, rm_depth;

    // Records a path into the tree.  If branch[n] is true, indicates
    // take greater branch from the nth node in the path, otherwise
    // take the less branch.  branch[0] gives branch from root, and
    // so on.
    bset branch;

    handle h = root;
    handle parent = null(), child;
    int cmp, cmp_shortened_sub_with_path;

    for ( ; ; )
      {
	if (h == null())
	  // No node in tree with given key.
	  return(null());
	cmp = cmp_k_n(k, h);
	if (cmp == 0)
	  // Found node to remove.
	  break;
	parent = h;
	h = cmp < 0 ? get_lt(h) : get_gt(h);
	if (read_error())
	  return(null());
	branch[depth++] = cmp > 0;
	cmp_shortened_sub_with_path = cmp;
      }
    handle rm = h;
    handle parent_rm = parent;
    rm_depth = depth;

    // If the node to remove is not a leaf node, we need to get a
    // leaf node, or a node with a single leaf as its child, to put
    // in the place of the node to remove.  We will get the greatest
    // node in the less subtree (of the node to remove), or the least
    // node in the greater subtree.  We take the leaf node from the
    // deeper subtree, if there is one.

    if (get_bf(h) < 0)
      {
	child = get_lt(h);
	branch[depth] = false;
	cmp = -1;
      }
    else
      {
	child = get_gt(h);
	branch[depth] = true;
	cmp = 1;
      }
    if (read_error())
      return(null());
    depth++;

    if (child != null())
      {
	cmp = -cmp;
	do
	  {
	    parent = h;
	    h = child;
	    if (cmp < 0)
	      {
		child = get_lt(h);
		branch[depth] = false;
	      }
	    else
	      {
		child = get_gt(h);
		branch[depth] = true;
	      }
	    if (read_error())
	      return(null());
	    depth++;
	  }
	while (child != null());

	if (parent == rm)
	  // Only went through do loop once.  Deleted node will be replaced
	  // in the tree structure by one of its immediate children.
	  cmp_shortened_sub_with_path = -cmp;
        else
	  cmp_shortened_sub_with_path = cmp;

	// Get the handle of the opposite child, which may not be null.
	child = cmp > 0 ? get_lt(h, false) : get_gt(h, false);
      }

    if (parent == null())
      // There were only 1 or 2 nodes in this tree.
      root = child;
    else if (cmp_shortened_sub_with_path < 0)
      set_lt(parent, child);
    else
      set_gt(parent, child);

    // "path" is the parent of the subtree being eliminated or reduced
    // from a depth of 2 to 1.  If "path" is the node to be removed, we
    // set path to the node we're about to poke into the position of the
    // node to be removed.
    handle path = parent == rm ? h : parent;

    if (h != rm)
      {
	// Poke in the replacement for the node to be removed.
	set_lt(h, get_lt(rm, false));
	set_gt(h, get_gt(rm, false));
	set_bf(h, get_bf(rm));
	if (parent_rm == null())
	  root = h;
	else
	  {
	    depth = rm_depth - 1;
	    if (branch[depth])
	      set_gt(parent_rm, h);
	    else
	      set_lt(parent_rm, h);
	  }
      }

    if (path != null())
      {
	// Create a temporary linked list from the parent of the path node
	// to the root node.
	h = root;
	parent = null();
	depth = 0;
	while (h != path)
	  {
	    if (branch[depth++])
	      {
	        child = get_gt(h);
		set_gt(h, parent);
	      }
	    else
	      {
	        child = get_lt(h);
		set_lt(h, parent);
	      }
	    if (read_error())
	      return(null());
	    parent = h;
	    h = child;
	  }

	// Climb from the path node to the root node using the linked
	// list, restoring the tree structure and rebalancing as necessary.
	bool reduced_depth = true;
	int bf;
	cmp = cmp_shortened_sub_with_path;
	for ( ; ; )
	  {
	    if (reduced_depth)
	      {
		bf = get_bf(h);
		if (cmp < 0)
		  bf++;
		else  // cmp > 0
		  bf--;
		if ((bf == -2) || (bf == 2))
		  {
		    h = balance(h);
		    if (read_error())
		      return(null());
		    bf = get_bf(h);
		  }
		else
		  set_bf(h, bf);
		reduced_depth = (bf == 0);
	      }
	    if (parent == null())
	      break;
	    child = h;
	    h = parent;
	    cmp = branch[--depth] ? 1 : -1;
	    if (cmp < 0)
	      {
		parent = get_lt(h);
		set_lt(h, child);
	      }
	    else
	      {
		parent = get_gt(h);
		set_gt(h, child);
	      }
	    if (read_error())
	      return(null());
	  }
	root = h;
      }

    return(rm);
  }

// I tried to avoid having a separate base_avl_tree template by having
// bitset<max_depth> be the default for the bset template, but Visual
// C++ would not permit this.  It may possibly be desirable to use
// base_avl_tree directly with an optimized version of bset.
//
template <class abstractor, unsigned max_depth = 32>
class avl_tree
  : public base_avl_tree<abstractor, max_depth, std::bitset<max_depth> >
  { };

} // end namespace abstract_container

#endif

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久精品一区二区三区不卡牛牛| 蜜桃视频在线一区| 日韩av高清在线观看| 国产成人h网站| 欧美一级在线观看| 亚洲精品自拍动漫在线| 国产一区在线看| 91麻豆精品国产91久久久使用方法 | 在线播放视频一区| 国产精品午夜电影| 国产在线视频一区二区| 91 com成人网| 午夜精品久久久久久久久久久 | 91麻豆精品国产91久久久 | 久久精品欧美日韩精品| 麻豆国产精品777777在线| 在线观看亚洲专区| 中文字幕一区二区三区精华液| 国产精品亚洲一区二区三区妖精 | 国产精品美女久久久久aⅴ | 久久国产精品免费| 欧美精品久久一区二区三区| 亚洲最快最全在线视频| 99re6这里只有精品视频在线观看| 国产欧美日韩在线视频| 国产乱码精品一区二区三 | 欧美精品在线观看播放| 亚洲影院免费观看| 欧美亚州韩日在线看免费版国语版| 1000精品久久久久久久久| 成人综合激情网| 国产精品沙发午睡系列990531| 成人av在线网| 1024亚洲合集| 欧美亚洲免费在线一区| 一区二区三区欧美日| 欧美亚洲综合另类| 青青草视频一区| wwww国产精品欧美| 国产99久久久国产精品潘金 | 国产精品蜜臀av| 99re8在线精品视频免费播放| 亚洲免费看黄网站| 欧美伊人久久大香线蕉综合69| 天天综合日日夜夜精品| 欧美一级爆毛片| 国产盗摄女厕一区二区三区| 亚洲国产精品激情在线观看| www.成人在线| 婷婷夜色潮精品综合在线| 亚洲精品在线观| av电影天堂一区二区在线观看| 一区二区三区在线播放| 欧美福利电影网| 国产老妇另类xxxxx| 亚洲欧洲www| 3d动漫精品啪啪1区2区免费 | 人禽交欧美网站| 久久蜜桃一区二区| 色综合 综合色| 麻豆成人综合网| 日韩一区在线播放| 欧美人伦禁忌dvd放荡欲情| 精品一区二区av| 亚洲色欲色欲www| 在线播放中文字幕一区| 北条麻妃国产九九精品视频| 亚洲午夜电影网| 国产婷婷色一区二区三区在线| 91国产成人在线| 国产最新精品免费| 一区二区三区日韩精品| xnxx国产精品| 欧美日韩电影一区| av网站免费线看精品| 日韩av电影天堂| 综合久久久久综合| 精品国产三级a在线观看| 色94色欧美sute亚洲线路一ni| 久久99精品一区二区三区| 亚洲精品乱码久久久久久黑人 | 欧美精品一区二区三区蜜桃视频| 91老师国产黑色丝袜在线| 久久黄色级2电影| 日韩理论在线观看| 精品国产一区二区三区不卡| 欧美曰成人黄网| 丁香亚洲综合激情啪啪综合| 另类成人小视频在线| 亚洲成人av在线电影| 亚洲日穴在线视频| 欧美高清在线一区二区| 精品国产麻豆免费人成网站| 欧美老人xxxx18| 91国产免费观看| 91麻豆国产福利在线观看| 国产盗摄一区二区三区| 国产一区二区三区最好精华液| 天天综合网 天天综合色| 亚洲一区二区在线免费看| 中文字幕日本乱码精品影院| 久久亚洲捆绑美女| 精品日本一线二线三线不卡 | 欧美中文一区二区三区| www.成人在线| 9久草视频在线视频精品| 国产成人精品网址| 国产精品99久久久久久宅男| 激情文学综合网| 精品中文av资源站在线观看| 久久99久国产精品黄毛片色诱| 久久国产福利国产秒拍| 蜜桃av一区二区在线观看 | 国产亚洲欧美中文| 久久综合成人精品亚洲另类欧美| 日韩午夜中文字幕| 日韩一区二区影院| 精品国产1区二区| 久久人人爽人人爽| 欧美国产日韩亚洲一区| 中文字幕成人av| 亚洲激情在线激情| 午夜精品久久久久久久99樱桃| 日韩国产高清在线| 久久66热re国产| 成人丝袜高跟foot| 91福利视频网站| 欧美日韩高清在线播放| 91精品国产乱码| 久久久蜜桃精品| 亚洲乱码日产精品bd| 亚洲成人三级小说| 男男gaygay亚洲| 国产精品一区二区久久精品爱涩 | 国产精品18久久久久久久久 | 秋霞电影一区二区| 国产 欧美在线| 在线观看91视频| 久久综合色播五月| ...av二区三区久久精品| 亚洲一级电影视频| 精品一二三四区| 色综合天天综合网天天狠天天 | 亚洲大片一区二区三区| 综合激情网...| 亚洲成av人影院| 国产一区二区91| 日本精品一级二级| 欧美一区二区成人| 国产精品免费网站在线观看| 亚洲电影激情视频网站| 国产激情偷乱视频一区二区三区| 日本道免费精品一区二区三区| 欧美一区二区三区视频免费| 国产欧美日韩久久| 午夜精品久久久久久久99水蜜桃| 国产成人午夜精品影院观看视频| 欧美主播一区二区三区| 国产午夜精品美女毛片视频| 午夜精品成人在线| 99r精品视频| 国产亚洲欧美在线| 免费看黄色91| 在线视频你懂得一区| 国产欧美日韩久久| 免费成人小视频| 欧美色视频在线| 国产精品欧美一级免费| 久久精品国产99久久6| 欧美日韩一区二区在线观看视频| 中文在线一区二区| 理论电影国产精品| 欧美挠脚心视频网站| 亚洲精品成人在线| www.性欧美| 国产精品视频一区二区三区不卡| 免费高清在线一区| 91超碰这里只有精品国产| 18涩涩午夜精品.www| 成人激情综合网站| 久久一二三国产| 国产一区二区三区四区五区入口| 欧美一区二区三区在线电影 | 九色|91porny| 777午夜精品视频在线播放| 亚洲免费观看高清在线观看| www.日韩大片| 自拍偷拍亚洲综合| 99re这里只有精品6| 国产精品久久久久一区二区三区| 国产成人三级在线观看| 2023国产精华国产精品| 久久av资源网| 日韩视频不卡中文| 精品一区在线看| 精品国产一区二区三区久久影院| 久久成人av少妇免费| 欧美tk—视频vk| 精品一区二区三区蜜桃| 精品国产3级a|