#include <iostream>
using namespace std;

int main() {
	int intArrayList[] = {4, 6, 2, 10, 9};

	cout << "Unsorted list  :  ";
	for(int i = 0; i < sizeof(intArrayList)/sizeof(int); i++) {
		cout << intArrayList[i] << " ";
	}

	intArrayList = InsertionSort(intArrayList);
	
	for(int i = 0; i < sizeof(intArrayList)/sizeof(int); i++) {
		cout << intArrayList[i] << " ";
	}

	cout << endl << endl;
	system("pause");
}

int InsertionSort(int intArray[]) {
	int i, j, newValue;

	for(i = 1; i < (sizeof(intArray)/sizeof(int)); i++) {
		newValue = intArray[i];
		j = i;
		while(j > 0 && intArray[j - 1] > newValue) {
			intArray[j] = intArray[j - 1];
			j--;
		}
		intArray[j] = newValue;
	}
	return intArray;
}

the red coloured ones are the causes of the errors. but what am i doing wrong?

You cannot do that with regular arrays, sorry. But its a simple fix if you
use vectors.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.