about | help | code help+videos | done | prefs |
Write a method that returns a new copy of an array, but with each element shifted left or right by 'howFar' locations in the array. The whole array will either be shifted left by 'howFar' if 'left' is true, but otherwise will be shifted right. As preconditions you may assume that 'howFar' will be a positive number less than the length of the array. Since 'howFar' must be positive and smaller than the length of the array, that makes the smallest allowed value of 'howFar' ONE. Since the array must be longer than that, the smallest allowed array has length TWO. You may not use ArrayList or any other preexisting object-oriented data structures. Look at the test data for examples. quiz2021_10_21_SLHL_shift([17, 326, 457, 1235, 1235, 568, 235, 348, 152, 45], 4, false) → [235, 348, 152, 45, 17, 326, 457, 1235, 1235, 568] quiz2021_10_21_SLHL_shift([1, 4, 18, 24, 534, 9348, 91241, 98535], 3, true) → [24, 534, 9348, 91241, 98535, 1, 4, 18] quiz2021_10_21_SLHL_shift([142, 55, 346, 241, 124, 756], 2, true) → [346, 241, 124, 756, 142, 55] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 250
Copyright Nick Parlante 2017 - privacy