#!/usr/bin/env python#-*-coding:utf-8-*-#@Time: 2018/4/29 9:11#@Author: Jackendoff#@Site:#@File: Two-point tree. PY#@Software: PycharmData= [1,3,6,7,12,14,16,17,18,20,21,22,23,30,32,35]defBinary_serch (dataset,find_num):Print(DataSet)ifLen (DataSet) > 1: Mid= Int (len (DataSet)/2) ifDataset[mid] = =Find_num:Print('Find number%s'%find_num)elifDataset[mid] >Find_num:Print('the number found is to the left of%s'%Dataset[mid])returnBinary_serch (dataset[0:mid],find_num)Else: Print("the number found is to the right of%s"%Dataset[mid])returnBinary_serch (dataset[mid+1:],find_num)Else: ifDataset[0] = =Find_num:Print('Find Numbers') Else: Print('There's no such number .') Binary_serch (data,35)#The results are as followsD:\untitled\venv\Scripts\python.exe D:/untitled/bogls/two-point tree. py[1, 3, 6, 7, 12, 14, 16, 17, 18, 20, 21, 22, 23, 30, 32, 35] Find the number on the 18 right [20, 21, 22, 23, 30, 32, 35] Find the number on the 23 right [30, 32, 35] Find the number on the 32 right [35] Find the number process finished with exit code 0
Two-point lookup (Python)