Searching and Sorting
# Sequential Searchdef seq_search(arr, ele):pos = 0 while len(arr) > pos:if arr[pos] == ele:return Trueelse:pos += 1 return False o = seq_search([1, 2, 3,], 3)print(o) # 결과True # Binary Searchdef binary_search(arr, ele):first = 0last = len(arr) - 1 found = False while first arr[k + 1]:temp = arr[k]arr[k] = arr[k + 1]arr[k + 1] = tempreturn arr arr = [5, 3, 7, 2]o = bubble_sort(arr)print(o) # 결과[..
Python
2016. 5. 31. 12:53