Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- filename = "gg.txt"
- cwd = os.getcwd()
- print(cwd)
- data = [20,40,90,50,60,70,80,110,30]
- what_to_find = 110
- def findfile(file):
- data = []
- for root, dirs, files in os.walk('C:\\'):
- print ("searching..."), root
- if file in files:
- with open(join(strroot, file),"r") as k:
- for line in k:
- data.append(line)
- return(data)
- def bubbleSort(arr):
- isSorted = False
- while not(isSorted):
- for i in range(len(arr) - 1):
- for j in range(len(arr) - 1 - i):
- if arr[j] > arr[j+1]:
- arr[j], arr[j+1] = arr[j+1],arr[j]
- else:
- isSorted = True
- return (arr)
- def selectionSort(arr):
- for i in range(len(arr)):
- minpos = 0
- for j in range(i,len(arr)):
- if arr[j] < arr[minpos]:
- minpos = j
- temp = arr[i]
- arr[i],arr[minpos] = arr[minpos],temp
- arr.append(arr[0])
- arr.pop(0)
- return (arr)
- def insertionSort(arr):
- for i in range(len(arr)):
- element = arr[i]
- pos = i
- while (pos > 0 and arr[pos-1] > element):
- arr[pos] = arr[pos-1]
- pos = pos - 1
- arr[pos] = element
- return (arr)
- def binarySearch(arr,target):
- low = 0
- high = len(arr)
- while low <= high:
- mid = (low + high) // 2
- if target == arr[mid]:
- return (True,mid)
- elif target < arr[mid]:
- high = mid - 1
- elif target > arr[mid]:
- low = mid + 1
- return (False,None)
- didfind,position= binarySearch(data,what_to_find)
- print("BinarySearch: Found",what_to_find,"in position ",position)
- print("BubbleSort:",bubbleSort(data))
- print("SelectionSort:",selectionSort(data))
- print("InsertionSort",insertionSort(data))
- print("Data Found:",findfile(filename))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement