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

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

?? r2btree.c

?? 這是一個C程序分析工具
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*====================================================================*/
/*  FILE   :   @(#)r2btree.c	1.1  -  05/12/98 */
/*====================================================================*/
/*  PURPOSE:  Abstract Data Type implementation of a height balanced  */
/*	      binary tree.  This code was downloaded from the web and */
/*            used with permission.				      */
/*                                                                    */
/*  SYSTEM :  RECON II                                                */
/*                                                                    */
/*  USED BY:  main(), ReadTestData(), BuildCompList(), SelectComp(),  */
/*            and AnnotateSource().		                      */
/*                                                                    */
/*  HISTORY:                                                          */
/*  VER   DATE       AUTHOR        DESCRIPTION                        */
/*  1.00  20 Apr 98  A. Conwell    Added to recon
/*--------------------------------------------------------------------*/

/*
 * Copyright (C) 1995-1997 by Sam Rushing <rushing@nightmare.com>
 * 
 *                         All Rights Reserved
 * 
 * Permission to use, copy, modify, and distribute this software and
 * its documentation for any purpose and without fee is hereby
 * granted, provided that the above copyright notice appear in all
 * copies and that both that copyright notice and this permission
 * notice appear in supporting documentation, and that the name of Sam
 * Rushing not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior
 * permission.
 * 
 * SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 * NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

/* $Id: avl.c,v 2.6 1998/03/04 02:24:46 rushing Exp $ */

/*
 * This is a fairly straightfoward translation of a prototype
 * written in python, 'avl_tree.py'. Read that file first.
 */

#include <stdio.h>
#include <stdlib.h>

#include "r2btree.h"

avl_node *
new_avl_node (void *		key,
	      avl_node *	parent)
{
  avl_node * node = (avl_node *) malloc (sizeof (avl_node));

  if (!node) {
    return NULL;
  } else {
    node->parent = parent;
    node->key = key;
    node->left = NULL;
    node->right = NULL;
    SET_BALANCE (node, 0);
    SET_RANK (node, 1);
    return node;
  }
}	     

avl_tree *
new_avl_tree (avl_key_compare_fun_type compare_fun,
	      void * compare_arg)
{
  avl_tree * t = (avl_tree *) malloc (sizeof (avl_tree));

  if (!t) {
    return NULL;
  } else {
    avl_node * root = new_avl_node((void *)NULL, (avl_node *) NULL);
    if (!root) {
      return NULL;
    } else {
      t->root = root;
      t->height = 0;
      t->length = 0;
      t->curr = (avl_node *)NULL;
      t->compare_fun = compare_fun;
      t->compare_arg = compare_arg;
      return t;
    }
  }
}
  
void
free_avl_tree_helper (avl_node * node, avl_free_key_fun_type free_key_fun)
{
  if (node->left) {
    free_avl_tree_helper (node->left, free_key_fun);
  }
  free_key_fun (node->key);
  if (node->right) {
    free_avl_tree_helper (node->right, free_key_fun);
  }
  free (node);
}

void
free_avl_tree (avl_tree * tree, avl_free_key_fun_type free_key_fun)
{
  if (tree->length) {
    free_avl_tree_helper (tree->root->right, free_key_fun);
  }
  if (tree->root) {
    free (tree->root);
  }
  free (tree);
}

int
insert_by_key (avl_tree * ob,
	       void * key)
{
  if (!(ob->root->right)) {
    avl_node * node = new_avl_node (key, ob->root);
    if (!node) {
      return -1;
    } else {
      ob->root->right = node;
      ob->length = ob->length + 1;
      return 0;
    }
  } else { /* not self.right == None */
    avl_node *t, *p, *s, *q, *r;
    int a;

    t = ob->root;
    s = p = t->right;

    while (1) {
      if (ob->compare_fun (ob->compare_arg, key, p->key) < 1) {
	/* move left */
	SET_RANK (p, (GET_RANK (p) + 1));
	q = p->left;
	if (!q) {
	  /* insert */
	  avl_node * q_node = new_avl_node (key, p);
	  if (!q_node) {
	    return (-1);
	  } else {
	    q = q_node;
	    p->left = q;
	    break;
	  }
	} else if (GET_BALANCE(q)) {
	  t = p;
	  s = q;
	}
	p = q;
      } else {
	/* move right */
	q = p->right;
	if (!q) {
	  /* insert */
	  avl_node * q_node = new_avl_node (key, p);
	  if (!q_node) {
	    return -1;
	  } else {
	    q = q_node;
	    p->right = q;
	    break;
	  }
	} else if (GET_BALANCE(q)) {
	  t = p;
	  s = q;
	}
	p = q;
      }
    }
    
    ob->length = ob->length + 1;
    
    /* adjust balance factors */
    if (ob->compare_fun (ob->compare_arg, key, s->key) < 1) {
      r = p = s->left;
    } else {
      r = p = s->right;
    }
    while (p != q) {
      if (ob->compare_fun (ob->compare_arg, key, p->key) < 1) {
	SET_BALANCE (p, -1);
	p = p->left;
      } else {
	SET_BALANCE (p, +1);
	p = p->right;
      }
    }
    
    /* balancing act */
    
    if (ob->compare_fun (ob->compare_arg, key, s->key) < 1) {
      a = -1;
    } else {
      a = +1;
    }
    
    if (GET_BALANCE (s) == 0) {
      SET_BALANCE (s, a);
      ob->height = ob->height + 1;
      return 0;
    } else if (GET_BALANCE (s) == -a) {
      SET_BALANCE (s, 0);
      return 0;
    } else if (GET_BALANCE(s) == a) {
      if (GET_BALANCE (r) == a) {
	/* single rotation */
	p = r;
	if (a == -1) {
	  s->left = r->right;
	  if (r->right) {
	    r->right->parent = s;
	  }
	  r->right = s;
	  s->parent = r;
	  SET_RANK (s, (GET_RANK (s) - GET_RANK (r)));
	} else {
	  s->right = r->left;
	  if (r->left) {
	    r->left->parent = s;
	  }
	  r->left = s;
	  s->parent = r;
	  SET_RANK (r, (GET_RANK (r) + GET_RANK (s)));
	}
	SET_BALANCE (s, 0);
	SET_BALANCE (r, 0);
      } else if (GET_BALANCE (r) == -a) {
	/* double rotation */
	if (a == -1) {
	  p = r->right;
	  r->right = p->left;
	  if (p->left) {
	    p->left->parent = r;
	  }
	  p->left = r;
	  r->parent = p;
	  s->left = p->right;
	  if (p->right) {
	    p->right->parent = s;
	  }
	  p->right = s;
	  s->parent = p;
	  SET_RANK (p, (GET_RANK (p) + GET_RANK (r)));
	  SET_RANK (s, (GET_RANK (s) - GET_RANK (p)));
	} else {
	  p = r->left;
	  r->left = p->right;
	  if (p->right) {
	    p->right->parent = r;
	  }
	  p->right = r;
	  r->parent = p;
	  s->right = p->left;
	  if (p->left) {
	    p->left->parent = s;
	  }
	  p->left = s;
	  s->parent = p;
	  SET_RANK (r, (GET_RANK (r) - GET_RANK (p)));
	  SET_RANK (p, (GET_RANK (p) + GET_RANK (s)));
	}
	if (GET_BALANCE (p) == a) {
	  SET_BALANCE (s, -a);
	  SET_BALANCE (r, 0);
	} else if (GET_BALANCE (p) == -a) {
	  SET_BALANCE (s, 0);
	  SET_BALANCE (r, a);
	} else {
	  SET_BALANCE (s, 0);
	  SET_BALANCE (r, 0);
	}
	SET_BALANCE (p, 0);
      }
      /* finishing touch */
      if (s == t->right) {
	t->right = p;
      } else {
	t->left = p;
      }
      p->parent = t;
    }
  }
  return 0;
}

int
get_item_by_index (avl_tree * tree,
		   unsigned long index,
		   void ** value_address)
{
  avl_node * p = tree->root->right;
  unsigned long m = index + 1;
  while (1) {
    if (!p) {
      return -1;
    }
    if (m < GET_RANK(p)) {
      p = p->left;
    } else if (m > GET_RANK(p)) {
      m = m - GET_RANK(p);
      p = p->right;
    } else {
      *value_address = p->key;
      return 0;
    }
  }
}
		   
int
get_item_by_key (avl_tree * tree,
		 void * key,
		 void **value_address)
{
  avl_node * x = tree->root->right;

/*  Make sure that tree has some elements before going on. */
  if (x==NULL)
    return -1;
/*  Make sure key is something other than NULL! */
  if (key==NULL)
    return -1;

  while (1) {
    int compare_result = tree->compare_fun (tree->compare_arg, key, x->key);
    if (compare_result < 0) {
      if (x->left) {
	x = x->left;
      } else {
	return -1;
      }
    } else if (compare_result > 0) {
      if (x->right) {
	x = x->right;
      } else {
	return -1;
      }
    } else {
      *value_address = x->key;
      return 0;
    }
  }
}

int
remove_by_key (avl_tree * tree,
	       void * key,
	       avl_free_key_fun_type free_key_fun)
{
  avl_node *x, *y, *p, *q, *r, *top, *x_child;
  int shortened_side, shorter;
  
  x = tree->root->right;
  while (1) {
    int compare_result = tree->compare_fun (tree->compare_arg, key, x->key);
    if (compare_result < 0) {
      /* move left
       * We will be deleting from the left, adjust this node's
       * rank accordingly
       */
      SET_RANK (x, (GET_RANK(x) - 1));
      if (x->left) {
	x = x->left;
      } else {
	/* Oops! now we have to undo the rank changes
	 * all the way up the tree
	 */
	SET_RANK(x, (GET_RANK (x) + 1));
	while (x != tree->root->right) {
	  if (x->parent->left == x) {
	    SET_RANK(x->parent, (GET_RANK (x->parent) + 1));
	  }
	  x = x->parent;
	}
	return -1;		/* key not in tree */
      }
    } else if (compare_result > 0) {
      /* move right */
      if (x->right) {
	x = x->right;
      } else {
	SET_RANK(x, (GET_RANK (x) + 1));
	while (x != tree->root->right) {
	  if (x->parent->left == x) {
	    SET_RANK(x->parent, (GET_RANK (x->parent) + 1));
	  }
	  x = x->parent;
	}
	return -1;		/* key not in tree */
      }
    } else {
      break;
    }
  }

  if (x->left && x->right) {
    void * temp_key;

    /* The complicated case.
     * reduce this to the simple case where we are deleting
     * a node with at most one child.
     */
    
    /* find the immediate predecessor <y> */
    y = x->left;
    while (y->right) {
      y = y->right;
    }
    /* swap <x> with <y> */
    temp_key = x->key;
    x->key = y->key;
    y->key = temp_key;
    /* we know <x>'s left subtree lost a node because that's
     * where we took it from
     */
    SET_RANK (x, (GET_RANK (x) - 1));
    x = y;
  }
  /* now <x> has at most one child
   * scoot this child into the place of <x>
   */
  if (x->left) {
    x_child = x->left;
    x_child->parent = x->parent;
  } else if (x->right) {
    x_child = x->right;
    x_child->parent = x->parent;
  } else {
    x_child = NULL;
  }

  /* now tell <x>'s parent that a grandchild became a child */
  if (x == x->parent->left) {
    x->parent->left = x_child;
    shortened_side = -1;
  } else {
    x->parent->right = x_child;
    shortened_side = +1;
  }

  /*
   * the height of the subtree <x>
   * has now been shortened.  climb back up
   * the tree, rotating when necessary to adjust
   * for the change.
   */
  shorter = 1;
  p = x->parent;
  
  /* return the key and node to storage */
  free_key_fun (x->key);
  free (x);

  while (shorter && p->parent) {
    
    /* case 1: height unchanged */
    if (GET_BALANCE(p) == 0) {
      if (shortened_side == -1) {
	/* we removed a left child, the tree is now heavier
	 * on the right
	 */
	SET_BALANCE (p, +1);
      } else {
	/* we removed a right child, the tree is now heavier
	 * on the left
	 */
	SET_BALANCE (p, -1);
      }
      shorter = 0;
      
    } else if (GET_BALANCE (p) == shortened_side) {
      /* case 2: taller subtree shortened, height reduced */
      SET_BALANCE (p, 0);
    } else {
      /* case 3: shorter subtree shortened */
      top = p->parent;
      /* set <q> to the taller of the two subtrees of <p> */
      if (shortened_side == 1) {
	q = p->left;
      } else {
	q = p->right;
      }
      if (GET_BALANCE (q) == 0) {
	/* case 3a: height unchanged */
	if (shortened_side == -1) {
	  /* single rotate left */
	  q->parent = p->parent;
	  p->right = q->left;
	  if (q->left) {
	    q->left->parent = p;
	  }
	  q->left = p;
	  p->parent = q;
	  SET_RANK (q, (GET_RANK (q) + GET_RANK (p)));
	} else {
	  /* single rotate right */
	  q->parent = p->parent;
	  p->left = q->right;
	  if (q->right) {
	    q->right->parent = p;
	  }
	  q->right = p;
	  p->parent = q;
	  SET_RANK (p, (GET_RANK (p) - GET_RANK (q)));
	}
	shorter = 0;
	SET_BALANCE (q, shortened_side);
	SET_BALANCE (p, (- shortened_side));
      } else if (GET_BALANCE (q) == GET_BALANCE (p)) {
	/* case 3b: height reduced */
	if (shortened_side == -1) {
	  /* single rotate left */
	  q->parent = p->parent;
	  p->right = q->left;
	  if (q->left) {
	    q->left->parent = p;
	  }
	  q->left = p;
	  p->parent = q;
	  SET_RANK (q, (GET_RANK (q) + GET_RANK (p)));
	} else {
	  /* single rotate right */
	  q->parent = p->parent;
	  p->left = q->right;
	  if (q->right) {
	    q->right->parent = p;
	  }
	  q->right = p;
	  p->parent = q;
	  SET_RANK (p, (GET_RANK (p) - GET_RANK (q)));
	}
	shorter = 1;
	SET_BALANCE (q, 0);
	SET_BALANCE (p, 0);
      } else {
	/* case 3c: height reduced, balance factors opposite */
	if (shortened_side == 1) {
	  /* double rotate right */
	  /* first, a left rotation around q */
	  r = q->right;
	  r->parent = p->parent;
	  q->right = r->left;
	  if (r->left) {
	    r->left->parent = q;
	  }
	  r->left = q;
	  q->parent = r;
	  /* now, a right rotation around p */
	  p->left = r->right;
	  if (r->right) {
	    r->right->parent = p;
	  }
	  r->right = p;
	  p->parent = r;
	  SET_RANK (r, (GET_RANK (r) + GET_RANK (q)));
	  SET_RANK (p, (GET_RANK (p) - GET_RANK (r)));
	} else {
	  /* double rotate left */
	  /* first, a right rotation around q */
	  r = q->left;
	  r->parent = p->parent;
	  q->left = r->right;
	  if (r->right) {
	    r->right->parent = q;
	  }
	  r->right = q;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久99久久精品欧美| 国产精品欧美一级免费| 欧美激情一区二区三区在线| 一级日本不卡的影视| 国产永久精品大片wwwapp | 91高清视频免费看| 欧美大胆人体bbbb| 亚洲一区二区三区四区在线观看 | 国产麻豆视频一区| 777色狠狠一区二区三区| 综合av第一页| 国产精品亚洲午夜一区二区三区 | 一片黄亚洲嫩模| 国产成人精品一区二区三区四区| 91精品国产色综合久久不卡电影 | 色噜噜狠狠一区二区三区果冻| 日韩免费在线观看| 婷婷综合另类小说色区| 一本到不卡免费一区二区| 国产精品久久久久四虎| 丁香啪啪综合成人亚洲小说| 欧美videos大乳护士334| 日本va欧美va精品| 欧美另类z0zxhd电影| 亚洲一区在线观看免费| 在线观看日韩电影| 亚洲精品免费一二三区| 色综合久久久久综合| 国产精品高潮久久久久无| 成人激情开心网| 欧美韩日一区二区三区四区| 国产a区久久久| 国产精品免费aⅴ片在线观看| 国产精品一二三区在线| 国产人久久人人人人爽| 国产激情一区二区三区| 国产日韩欧美综合在线| 国产成人免费视频网站| 日本一区二区综合亚洲| 不卡的av中国片| 亚洲精品日韩综合观看成人91| 色婷婷精品大视频在线蜜桃视频| 亚洲欧美日本韩国| 欧美日韩亚洲另类| 美日韩一级片在线观看| 久久一日本道色综合| 国产精品中文字幕日韩精品| 国产精品全国免费观看高清| 91免费观看视频| 香蕉久久夜色精品国产使用方法| 欧美日本乱大交xxxxx| 另类人妖一区二区av| 日本一区二区三区久久久久久久久不 | 欧美自拍丝袜亚洲| 丝袜美腿亚洲色图| 久久综合精品国产一区二区三区 | 欧美主播一区二区三区| 人禽交欧美网站| 国产日韩欧美综合在线| 色综合色狠狠天天综合色| 日本中文字幕一区二区有限公司| 久久久久国产精品麻豆ai换脸| 色先锋aa成人| 麻豆精品一二三| 综合久久国产九一剧情麻豆| 宅男噜噜噜66一区二区66| 国产精品正在播放| 亚洲在线视频免费观看| 久久影视一区二区| 欧美丝袜丝交足nylons| 国产成人午夜电影网| 亚洲最大成人网4388xx| 久久综合久久久久88| 色吧成人激情小说| 国产一区二区视频在线| 亚洲国产一区二区视频| 久久久亚洲精品一区二区三区| 91国产精品成人| 国产高清久久久| 五月婷婷久久丁香| 亚洲国产成人在线| 日韩欧美另类在线| 欧美综合一区二区| 国产a久久麻豆| 男人的天堂久久精品| 一区二区三区四区av| 国产精品无人区| 日韩欧美国产系列| 欧美日韩国产首页| 91丨porny丨首页| 国产成人啪午夜精品网站男同| 日本美女一区二区| 亚洲一区二区五区| 国产精品欧美久久久久一区二区| 欧美va亚洲va在线观看蝴蝶网| 欧美日韩中文精品| 91美女在线看| 成人午夜在线播放| 国产高清精品久久久久| 久久国产人妖系列| 日日摸夜夜添夜夜添国产精品| 亚洲免费观看高清完整版在线| 国产精品色婷婷| 中文字幕第一区二区| 国产日韩视频一区二区三区| 亚洲精品一区二区三区四区高清| 欧美高清视频www夜色资源网| 91黄色激情网站| 在线区一区二视频| 欧美午夜精品免费| 在线中文字幕一区| 色综合一个色综合| 91丨porny丨蝌蚪视频| 91免费视频网| 在线观看一区二区视频| 色视频一区二区| 欧美日免费三级在线| 欧美日韩大陆在线| 欧美一区二区三区在线| 日韩你懂的在线播放| 26uuu国产在线精品一区二区| 久久综合国产精品| 国产欧美一区二区在线| 国产精品白丝在线| 亚洲图片欧美一区| 日韩高清一区在线| 激情综合网最新| 国产成人av一区二区三区在线| 国产精品影视在线观看| 成人夜色视频网站在线观看| 91在线视频播放| 欧美亚洲国产怡红院影院| 欧美久久久久久久久中文字幕| 日韩一区二区在线看片| 久久久久国产精品人| 国产精品国产三级国产三级人妇| 一区二区三区四区中文字幕| 亚洲国产色一区| 美女久久久精品| 国产91丝袜在线播放0| 久久婷婷国产综合国色天香| 色综合天天性综合| 在线一区二区三区四区| 日韩一区和二区| 国产喂奶挤奶一区二区三区| 亚洲女与黑人做爰| 日韩av电影天堂| 国产成人综合网| 91久久一区二区| 欧美不卡一区二区三区| 国产精品国产三级国产a| 五月婷婷色综合| 国产xxx精品视频大全| 91电影在线观看| 精品国产凹凸成av人导航| 中文字幕一区二区在线观看| 五月综合激情婷婷六月色窝| 国产不卡视频在线观看| 欧美日韩国产经典色站一区二区三区| 久久久99免费| 午夜私人影院久久久久| 岛国一区二区在线观看| 欧美一区二区网站| 亚洲你懂的在线视频| 激情伊人五月天久久综合| 一本到不卡免费一区二区| 2023国产一二三区日本精品2022| 一区二区三区久久| 国产 日韩 欧美大片| 欧美一级午夜免费电影| 亚洲乱码日产精品bd| 国产成人8x视频一区二区| 91麻豆精品国产| 亚洲精品五月天| 99久久精品国产毛片| 久久久久九九视频| 久久99久久久久| 在线91免费看| 亚洲综合激情另类小说区| 99精品视频在线免费观看| 2020国产精品自拍| 日本成人在线一区| 欧美福利视频一区| 亚洲一区二区三区四区五区中文 | 日韩二区在线观看| 99精品视频在线观看| 久久久噜噜噜久久中文字幕色伊伊 | 日韩一区二区精品在线观看| 一区二区三区 在线观看视频| www.日本不卡| 国产精品久久久久一区二区三区| 国产乱子伦视频一区二区三区| 91精品国产综合久久久久久漫画| 亚洲最快最全在线视频| 日本高清不卡aⅴ免费网站| 国产精品久久午夜| 波多野结衣亚洲一区| 中文字幕在线观看不卡| 成人av午夜影院| 亚洲欧洲99久久|