So the purpose of this is code is to sort 10 integers numbers entered by user which is stored in the array and then passed to the function to sort it and then return it back. The issue I am having is at the function in the while loop and after where it is giving me a error that "expression must be a modifiable lvalue" at datasort[moveItem]=datasort[moveItem-1]; and datasort[moveItem]=insert;.
#include <iostream>
#include <iomanip>
usingnamespace std;
void insertionSort(constint [], int);
int main()
{
constint arraySize=10; // size of array a
int data[arraySize]={};
//loop for user entries of 10 numbers in array
for (int index=0; index<arraySize; index++)
{
cout<<"Unsorted array:\n";
cin>>data[index];
}
// output original array
for (int i = 0; i < arraySize; ++i )
{
cout << setw( 4 ) << data[ i ];
}
cout<<"\nSorted array:\n";
insertionSort(data, arraySize);
// output sorted array
for (int i=0; i<arraySize; ++i)
{
cout<<setw(4)<<data[i];
}
cout<<endl;
} // end main
void insertionSort(constint datasort[], int arraySize)
{
int insert; // temporary variable to hold element to insert
// insertion sort
// loop over the elements of the array
for (int next=1; next<arraySize; ++next)
{
insert=datasort[next]; // store the value in the current element
int moveItem=next; // initialize location to place element
// search for the location in which to put the current element
while ((moveItem>0) && (datasort[moveItem-1]>insert))
{
// shift element one slot to the right
datasort[moveItem]=datasort[moveItem-1];
--moveItem;
} // end while
datasort[moveItem]=insert; // place inserted element into the array
} // end for
return;
}//end of function