Есть ли чистый и быстрый способ найти мин и максимум массиваC++

Программы на C++. Форум разработчиков
Anonymous
Есть ли чистый и быстрый способ найти мин и максимум массива

Сообщение Anonymous »

Есть ли чистый и быстрый способ найти мин и максимум массива < /p>
int array1 [] = {2,6,10,22,12}; < /p>
Результаты < /p>
min = 2 /
max = 22 < /p>

min = 2 /
< /p>

min = 2 /
< /p>

= 2 /
< /p>
= 2 /
// Function
void min_max(set my_set)
{
for (auto i : my_set);
}

// Function to find the maximum element
int findMax(set my_set)
{

// Get the maximum element
int max_element;
if (!my_set.empty())
max_element = *(my_set.rbegin());

// return the maximum element
return max_element;
}

// Function to find the minimum element
int findMin(set my_set)
{

// Get the minimum element
int min_element;
if (!my_set.empty())
min_element = *my_set.begin();

// return the minimum element
return min_element;
}

int main()
{

// Get the set
set my_set = {2,6,10,22,12};
// results
findMin(my_set)
findMax(my_set)

}


Подробнее здесь: https://stackoverflow.com/questions/640 ... f-an-array

Вернуться в «C++»