size of array being inserted into array contents

I am trying to sort an array from smallest to largest. When the program runs, it sorts the array correctly, but replaces '25' with '5'. What I have figured out, is that it is replacing the size of the array. If i change the size, it changes the value that is inserted. Please help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
	const int SIZE = 5;			//number of integers to sort
	int numbers[SIZE] = { 15, 5, 10, 25, -8 };	//array if ints


 void sort(int *numbers, int array_size)
{
    int temp;
	//sorts the array from smallest to largest
	for (int i = 0; i < array_size; ++i)
	{
		for (int j = 0; j < array_size; ++j)
		{
			if (numbers[j] > numbers[j + 1])
                swap(numbers[j], numbers[j + 1]);
		}
	}
}
Line 11

Updated:
1
2
3
4
5
6
7
8
9
10
11
12
void sort(int *numbers, const int array_size)
{
	//sorts the array from smallest to largest
	for (int i = 0; i < array_size; ++i)
	{
		for (int j = 0; j < array_size-1; ++j)
		{
			if (numbers[j] > numbers[j + 1])
				std::swap(numbers[j], numbers[j + 1]);
		}
	}
}
Last edited on
ahhh thank you.
Topic archived. No new replies allowed.