void insertIntoArrayAnother(int * arr, int * arrOutput, int& n, int newElement)
{
int i = 0;
int k = 0;
bool elSet = false;
while (i < n)
{
if (arr[i] < newElement || elSet)
{
arrOutput[k] = arr[i];
i++;
k++;
}
else {
arrOutput[k] = newElement;
k++;
elSet = true;
}
}
n++;
}
int main()
{
int arr[9]{ 1,2,3,4,6,7,8,9 }; // 8 elements
int newArr[9];
int n = 8; // this is how many elements can be in the array
int newElement = 5;
insertIntoArrayAnother(arr, &newArr[0], n, newElement);
for (int i = 0; i < n; i++)
{
std::cout << newArr[n] << " ";
}
std::cout << std::endl;
system("pause");
}