顺序表的查找:
    直接循环依次和目标比较就行
有序表的查找(二分查找):
int search(SS *T,Type key){
    int mid;
    int low=1;
    int high=T.length;
    while(low<=high){
        mid=(low+high)/2;
        if(T.elem[mid]<key){
            low=mid+1;
        }else{
            high=mid-1;
        }
    }
    return high;
}
二叉树表的查找:返回从上到下从左到右的序号(层序遍历,也可以用栈非递归遍历):
int LevelSearch(BTNode *T,Type key){
    int front=-1;
    int rear=-1;
    BTNode *Q[100];
    Q[++rear]=T;
    printf("根节点的数据:",Q[rear]->data);
    while(front!=rear){
        BTNode *p;
        p=Q[++front];
        if(p->rTree){
            Q[++rear]=p->rTree;
            if(Q[rear]==key){
                return rear;
            }
        }
        if(p->lTree){
            Q[++rear]=p->lTree;
            if(Q[rear]==key){
                return rear;
            }
        }
    }
}

 

相关文章:

  • 2021-08-17
  • 2021-05-13
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
猜你喜欢
  • 2021-08-31
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-07-13
相关资源
相似解决方案