diff --git a/1]. DSA/1]. Data Structures/01]. Array/Python/_003)_Delete_Element.py b/1]. DSA/1]. Data Structures/01]. Array/Python/_003)_Delete_Element.py new file mode 100644 index 000000000..72c736c0b --- /dev/null +++ b/1]. DSA/1]. Data Structures/01]. Array/Python/_003)_Delete_Element.py @@ -0,0 +1,30 @@ +""" +Function to delete an element in an array + +Takes in an array and an element to delete + +Returns an new Array +""" + + +def delete(arr, element): + if element not in arr: + return "no such element exist in array" + + new_arr = [] + + for index in range(len(arr)): + if arr[index] != element: + new_arr.append(arr[index]) + + return new_arr + + +arr = [1, 2, 3, 5] +element = 2 + +print("Before deletion:", arr) +print("Deleting:", element) + +new_arr = delete(arr, element) +print("After deletion:", new_arr) diff --git a/1]. DSA/1]. Data Structures/01]. Array/Python/_004)_Reverse_Array.py b/1]. DSA/1]. Data Structures/01]. Array/Python/_004)_Reverse_Array.py new file mode 100644 index 000000000..4effc5bc1 --- /dev/null +++ b/1]. DSA/1]. Data Structures/01]. Array/Python/_004)_Reverse_Array.py @@ -0,0 +1,21 @@ +""" +Function to Reverse an Array + +Takes in an Array and Returns an New Array +""" + + +def reverse(arr): + new_arr = [] + + for index in range(len(arr)): + new_arr.insert(0, arr[index]) + + return new_arr + + +arr = [1, 2, 3, 4, 5] +new_arr = reverse(arr) + +print("Before Reverse:", arr) +print("After Reverse:", new_arr) diff --git a/1]. DSA/1]. Data Structures/01]. Array/Python/_005)_Left_Rotate_Array_by_1.py b/1]. DSA/1]. Data Structures/01]. Array/Python/_005)_Left_Rotate_Array_by_1.py new file mode 100644 index 000000000..e4ca80c10 --- /dev/null +++ b/1]. DSA/1]. Data Structures/01]. Array/Python/_005)_Left_Rotate_Array_by_1.py @@ -0,0 +1,21 @@ +""" +Function to rotate an the first element +""" + + +def left_rotate(arr, num): + tmp = arr[0] + + for index in range(1, num): + arr[index - 1] = arr[index] + + arr[num - 1] = tmp + + +arr = [1, 2, 3, 4, 5] +num = 2 + +print("Before Left Rotation:", arr) + +left_rotate(arr, num) +print("After '1' Left Rotation:", arr)