Running into a snag with an error

so my goal here for this assignment is to re-arrange my array from largest to smallest I'm aware my code isn't quite there yet however I'm getting stuck on this error I keep getting where 'Stack around the variable 'array' was corrupted.' I've looked and looked and I can't find where my error in the code is... Visual studio itself isn't throwing me any codes. I hate to post on here for help again but I really am a bit lost and when I research this error usually its because people aren't starting 'i' with 0 in their for loop and since that's not my issue I'm back to square one.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>

using namespace std;

int Largest(int arr[], int size);
int Search(int arr[], int size, int target);
void Print(int arr[], int size);


int main()
{
	int array[5] = { 13, 35, 0, 45, 80 };
	int largest = -1, size = 5, temp;

	for (int i = 0; i < size / 2; i++)
	{
		largest = Largest(array, size - i);
		temp = largest;
		array[Search(array, 5, largest)] = array[i];
		array[i] = temp;
		largest = -1;
	}
	Print(array, 5);
}


int Largest(int arr[], int size)
{
	int largest = -1;

	for (int i = 0; i < size; i++)
	{
		if (arr[i] > largest)
		{
			largest = arr[i];
		}
	}
	return largest;
}

void Print(int arr[], int size)
{
	for (int i = 0; i < size; i++)
	{
		cout << arr[i] << ' ';
	}
	cout << endl;
}

int Search(int arr[], int size, int target)
{
	for (int i = 0; i < size; i++)
	{
		if (i == target)
			return i;
	}
	return -1;
}
first thing i see..
You try to access array[search()] and search could possibly return -1.
foo.cpp|50 col 16| warning: unused parameter 'arr' [-Wunused-parameter]

your Search() function doesn't care about the array.
Topic archived. No new replies allowed.