文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Step 1: Search

Step 1: Search

时间:2010-10-06  来源:sohu2000000

5.5.1 Step 1: Search

The only difference between this search and an ordinary search in a BST is that we have to keep track of the nodes above the one we're deleting. We do this by pushing them onto the stack defined above. Each iteration through the loop compares item to p's data, pushes the node onto the stack, moves down in the proper direction. The first trip through the loop is something of an exception: we hard-code the comparison result to -1 so that the pseudo-root node is always the topmost node on the stack. When we find a match, we set item to the actual data item found, so that we can return it later.

 

165. <Step 1: Search AVL tree for item to delete 165> =
k = 0;
p = (struct avl_node *) &tree->avl_root;
for (cmp = -1; cmp != 0; 
cmp = tree->avl_compare (item, p->avl_data, tree->avl_param))
{ int dir = cmp > 0; pa[k] = p; da[k++] = dir; p = p->avl_link[dir]; if (p == NULL) return NULL; } item = p->avl_data;

This code is included in 164 and 220.

相关阅读 更多 +
排行榜 更多 +
野生恐龙射击生存安卓版

野生恐龙射击生存安卓版

飞行射击 下载
战场狙击手

战场狙击手

飞行射击 下载
无尽的三月七h5

无尽的三月七h5

休闲益智 下载