/*******************************************************************************
* Aiden Stannard // CS1A // Chapter 9 Homework: Challange 12# // 11/21/2026
* _____________________________________________________________________________
*
* Element Shifter
* _____________________________________________________________________________
*
* This program accepts an array and creates a copy of the array with every
* value of the new array moved up by a single element, assigning the first
* element of the new array to zero.
* _____________________________________________________________________________
*
* Input: result = shiftArray(arr, 3)
*
* Output: The new order of the values of the array are as follows:
* 0 10 20 30
*
******************************************************************************/
#include <iostream>
using namespace std;
int* shiftArray(int arr[], int size) { // moves element positionn of the passed
// array values up by one element
int* newArr = new int[size + 1];
newArr[0] = 0;
for (int i = 0; i < size; i++) {
newArr[i + 1] = arr[i];
}
return newArr;
}
int main() {
int size = 3;
int arr[size] = {10, 20, 30}; // Original array order
int* result; // Pointer that will take on the value of the returned pointer
// from the shiftarray function.
result = shiftArray(arr, size); // passes array and size to the function
cout << "The new order of the values of the array are as follows: " << endl;
for (int i = 0; i < 4; i++) { // Outputs the new array value positions
cout << result[i] << " ";
}
delete[] result; // frees the "borrowed" memory
return 0;
}