算法初识

#斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368
def func(arg1,arg2,stop):
    if arg1 == 0:
        print(arg1,arg2)
    arg3 = arg1 + arg2
    print(arg3)
    if arg3 < stop:
        func(arg2,arg3,stop)

func(0,1,30)
#算法二分查找
def binary_search(data_source,find_n):

    mid = int(len(data_source)/2)
    if len(data_source) >= 1:
        if data_source[mid] > find_n:
            print("data in left of [%s]"%data_source[mid])
            binary_search(data_source[:mid],find_n)
        elif data_source[mid] < find_n:
            print("data in right of [%s]" % data_source[mid])
            binary_search(data_source[mid:],find_n)
        else:
            print("found", data_source[mid])
    else:
        print("can't find.....")
if __name__ == '__main__':
    data = list(range(1,800))

    binary_search(data,500)

 

li = [32,54,32,2,765,34,87,44,1,4,7,33]
for i in range(len(li)):
for m in range(len(li)-1):
if li[m] > li[m+1]:
temp = li[m+1]
li[m+1] = li[m] #54 =>32
li[m] = temp #32 => 32

print(li)

 

posted on 2017-05-02 17:07  法海降妖  阅读(99)  评论(0编辑  收藏  举报