Array Bubble Sorting

Hi, I am having trouble setting an array of int values from low to high. The program does kind of work but it changes the highest value to a random value. I believe the problem lies somewhere within one of the for loops... but I cannot work it out..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
        int swapHolder = -1;
	int end = 10;
	int length = 10;
	int myArray[] = { 36, 12, 345, 732, 117, 532, 98, 54, 271, 344 };

	for(int counter = length - 1; counter > 0; counter--)	
	{
		for(int index = 0; index < end; index++)
		{
			if(myArray[index] > myArray[index+1])	{
				swapHolder = myArray[index+1];
				myArray[index+1] = myArray[index];
				myArray[index] = swapHolder;	
			}
		}

		for(int index = 0; index < 10; index++)
		{
			cout << myArray[index] << ", ";
		}
		cout << endl;
		end--;
	}


Please help!

Thanks
If index = 9, what number is at myArray[index+1]?
Topic archived. No new replies allowed.