//Andrew Alspaugh CS1A Chapter 9. P. 539 #12
/*****************************************************************************
Shift Elements in Array
______________________________________________________________________________
The purpose of this program is to use the function shift elements to shift
all of the elements from any given array
____________________________________________________________________________
Input
int size
int *array[]
Output
int *shifted[]
*****************************************************************************/
#include <iostream>
using namespace std;
int *ShiftElements(int *array, int& size);
int main()
{
//DATA DICTIONARY
int size;
//INPUT
cout << "Enter size of array:" << endl;
cin >> size;
int *array = new int [size];
cout << "enter " << size << " elements:" << endl;
for(int count = 0; count < size; count++)
cin >> *(array + count);
//PROCESS
int *shifted = ShiftElements(array, size);
//OUTPUT
cout << "Updated Array is:" << endl;
for(int count = 0; count < size; count++)
{
cout << *(shifted + count) << " ";
}
delete [] array;
delete[] shifted;
return 0;
}
int *ShiftElements(int *array, int& size)
{
size += 1;
int *shifted = new int [size];
*(shifted + 0) = 0;
for(int count = 0; count < size - 1; count++)
*(shifted + (count + 1)) = *(array + count);
return shifted;
}