diff --git a/left_rotate_by_D.cpp b/left_rotate_by_D.cpp new file mode 100644 index 0000000..b24d85f --- /dev/null +++ b/left_rotate_by_D.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; + + +void reverse(int arr[], int low, int high) +{ + while(low < high) + { + swap(arr[high], arr[low]); + + low++; + high--; + } +} + +void leftRotate(int arr[], int d, int n) +{ + reverse(arr, 0, d - 1); + + reverse(arr, d, n - 1); + + reverse(arr, 0, n - 1); +}