From 76379cacea6a30142b21469b072652adf2032654 Mon Sep 17 00:00:00 2001 From: sunny Date: Mon, 19 Oct 2020 14:12:13 +0530 Subject: [PATCH] Create left_rotation_array.py --- Python/Miscellaneous/left_rotation_array.py | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Python/Miscellaneous/left_rotation_array.py diff --git a/Python/Miscellaneous/left_rotation_array.py b/Python/Miscellaneous/left_rotation_array.py new file mode 100644 index 0000000..9a751ee --- /dev/null +++ b/Python/Miscellaneous/left_rotation_array.py @@ -0,0 +1,23 @@ +class arrayData(): + # Python3 program to + # Function to left rotate arr[] of size n by d*/ + def leftRotate(self, arr, d, n): + for i in range(d): + self.leftRotatebyOne(arr, n) + + # Function to left Rotate arr[] of size n by 1*/ + def leftRotatebyOne(self, arr, n): + temp = arr[0] + for i in range(n-1): + arr[i] = arr[i + 1] + arr[n-1] = temp + + + # utility function to print an array */ + def printArray(self, arr, size): + for i in range(size): + print ("% d"% arr[i], end =" ") +arrayObj = arrayData() +arr = [1, 2, 3, 4, 5, 6, 7] +arrayObj.leftRotate(arr, 3, 7) +arrayObj.printArray(arr, 7)