diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2025-01-10 22:40:26 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2025-01-10 22:40:26 +0200 |
commit | e2c4e882f9a549e01553b60c61fdbe8b52238cbe (patch) | |
tree | 44915efc3f1ce5db47ffc3a56263d883923326a9 | |
parent | 3681fd8150f0e13a19cbc0cf17582c5dceaab7eb (diff) | |
download | cs-y13-e2c4e882f9a549e01553b60c61fdbe8b52238cbe.tar.gz cs-y13-e2c4e882f9a549e01553b60c61fdbe8b52238cbe.tar.bz2 cs-y13-e2c4e882f9a549e01553b60c61fdbe8b52238cbe.zip |
fix(unix): dos2unix on files
-rw-r--r-- | algorithms/linear_search.py | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/algorithms/linear_search.py b/algorithms/linear_search.py index 5a54ce6..ae198d2 100644 --- a/algorithms/linear_search.py +++ b/algorithms/linear_search.py @@ -1,21 +1,21 @@ -import random
-def generate_test_data(length: int, _range: tuple):
- arr = []
- for i in range(length):
- arr.append(random.randint(_range[0], _range[1]))
- return arr
-def linsearch(myList: list, valueToFind: int):
- mindex: int = len(myList) - 1
- index: int = 0
- found = False
- while not found and index <= mindex:
- if myList[index] == valueToFind:
- found = True
- index += 1
- if found: print("VALUE FOUND!!!")
- else: print("OH NO ITEM NOT FOUND IN LIST!!")
-def main():
- inputFind = int(input("Value to find: "))
- linsearch(generate_test_data(10, (0, 1000)), inputFind)
-if __name__ == "__main__":
- main()
+import random +def generate_test_data(length: int, _range: tuple): + arr = [] + for i in range(length): + arr.append(random.randint(_range[0], _range[1])) + return arr +def linsearch(myList: list, valueToFind: int): + mindex: int = len(myList) - 1 + index: int = 0 + found = False + while not found and index <= mindex: + if myList[index] == valueToFind: + found = True + index += 1 + if found: print("VALUE FOUND!!!") + else: print("OH NO ITEM NOT FOUND IN LIST!!") +def main(): + inputFind = int(input("Value to find: ")) + linsearch(generate_test_data(10, (0, 1000)), inputFind) +if __name__ == "__main__": + main() |