Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Latest commit

 

History

History
61 lines (60 loc) · 2.05 KB

7.md

File metadata and controls

61 lines (60 loc) · 2.05 KB

1

  for(int i=1;i<m;++i)
	 {                
		 Hi=(H0+i)%m;     		//按照线性探测法计算下一个哈希地址Hi
        if (HT[Hi].key==NULLKEY) return -1;	//若单元Hi为空,则所查元素不存在
        else if (HT[Hi].key==key) return Hi; 	//若单元Hi中元素的关键字为key,则查找成功
     }//for
     return -1;

2

/*   
  if(!T) {                //找到插入位置,递归结束
   BSTree S = new BSTNode;            //生成新结点*S
    S->data = e;                 	//新结点*S的数据域置为e   
    S->lchild = S->rchild = NULL; //新结点*S作为叶子结点
    T =S;    //把新结点*S链接到已找到的插入位置
  }
*/
//上面的也是正确的! 
  if(!T) {                //找到插入位置,递归结束
         T = new BSTNode;      //生成新结点
         T->data = e;        //新结点的数据域置为e   
         T->lchild = T->rchild = NULL;	//新结点作为叶子结点
        
  }

3

	   mid=(low+high) / 2;
      if (key==ST.R[mid].key)  return mid;      		//找到待查元素
      else if (key<ST.R[mid].key)  return Search_Bin(ST,key,low,mid -1);
      else  return Search_Bin(ST,key,mid +1,high);

4

   mid=(low+high) / 2;
      if (key==ST.R[mid].key)  return mid;      		//找到待查元素
      else if (key<ST.R[mid].key)  high = mid -1;		//继续在前一子表进行查找
      else  low =mid +1;                       			//继续在后一子表进行查找

5

  if((!T)|| key==T->data.key) return T;       	            	//查找结束
  else if (key<T->data.key)  return SearchBST(T->lchild,key);	//在左子树中继续查找
  else return SearchBST(T->rchild,key);    		   			//在右子树中继续查找

6

     int i;
	 ST.R[0].key = key;                          			//“哨兵”
     for(i = ST.length; ST.R[i].key!=key; --i)  ;		//从后往前找
     return i;      
    /* 
	 int i; 
     for (int i=ST.length; i>=1; --i)  
             if (ST.R[i].key==key) return i;		//从后往前找        
     return 0;
    */