Created
July 27, 2021 18:42
-
-
Save code-reaper08/082c3030574ee689da2ae664aaa5e60d to your computer and use it in GitHub Desktop.
Final program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Reverse(samparr, begin, end) { | |
while (begin < end) { | |
temp = samparr[begin]; | |
samparr[begin] = samparr[end]; | |
samparr[end] = temp; | |
begin = begin + 1; | |
end = end - 1; | |
} | |
} | |
function Rotate(samparr, d, n) { | |
if (d == 0) { | |
return; | |
} | |
Reverse(samparr, 0, d - 1); | |
Reverse(samparr, d, n - 1); | |
Reverse(samparr, 0, n - 1); | |
} | |
function Logger(samparr, n) { | |
for (i = 0; i < n; i++) { | |
console.log(samparr[i]); | |
} | |
} | |
let inparray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; | |
let n = inparray.length; | |
let d = 5 | |
Rotate(inparray, d, n); | |
Logger(inparray, n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment