查找数组中元素

伪代码

        Set first to 0
Set last to length-1
Set found to FALSE
WHILE(first<=last AND NOT found)
    Set middle to (first+last)/2
    IF(item equals data [middle])
        Set found to TURE
ELSE
    IF(item < data[middle])
        Set last to middle - 1
    ELSE 
        Set first to middle + 1
Return found

测试

posted @ 2023-11-05 22:43  20231310王宏邦  阅读(6)  评论(0编辑  收藏  举报