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;
}
|