about | help | code help+videos | done | prefs |
insertFrontPartial
Write a method that inserts a value into the first location of a partially filled array (see note), shifting items to the right as needed. Only shift items that are in use. If the partially filled array is full, do not insert the value. size will always be at least 0 and at most the length of the array. Don't solve this by creating a new array. Rather, make all the changes in the given array, and return that array at the end of the method. NOTE: In a "partially filled" array, the variable size indicates how many of the elements in that array (beginning at index 0) actually are "in use". For example, given the array {4, 7, 2, 5, 1, 4, 8} and a size of 3 then only the first 3 elements in that array (4, 7, and 2) are actually considered "in use". insertFrontPartial([4, 7, 2, 5, 1, 4, 8], 3, 99) → [99, 4, 7, 2, 1, 4, 8] insertFrontPartial([7, 0, 0, 0], 1, 12) → [12, 7, 0, 0] insertFrontPartial([5, 10, 15], 2, 0) → [0, 5, 10] ...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: 200
Copyright Nick Parlante 2017 - privacy