From 616566d86eef84fcca14143001548bd28961d504 Mon Sep 17 00:00:00 2001 From: Finlay Kilcullen Date: Thu, 8 Oct 2020 11:02:44 +0100 Subject: [PATCH] Added linear Search algorithm --- .idea/.gitignore | 3 +++ .idea/inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/python_projects.iml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ LinearSearch.py | 14 ++++++++++++++ 7 files changed, 49 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/python_projects.iml create mode 100644 .idea/vcs.xml create mode 100644 LinearSearch.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d56657a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4f4e885 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/python_projects.iml b/.idea/python_projects.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/python_projects.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LinearSearch.py b/LinearSearch.py new file mode 100644 index 0000000..f027eaa --- /dev/null +++ b/LinearSearch.py @@ -0,0 +1,14 @@ +#Basic Linear Search + +# Defines function that searches through array +def linearsearch(arr, x): # Passes in target as x, and the array + for i in range(len(arr)): # Creates an index for length of array + if arr[i] == x: # Compares array value to searched value + return i # Returns index + return -1 + +arr = [1,2,3,4,5,6,7,8,9,10] # Defines array + +x = int(input("Enter a number between 1 and 10: ")) # Gets the user key value + +print("element found at index "+str(linearsearch(arr,x))) # Displays where the value is found \ No newline at end of file