i have array declaration
array<int, 5> niz;
Now i need to found maximum in that array and to remove it . How to achieve that with class array?
EDIT
so array size cant be modified, so can i swift two elements in array then?
i have array declaration
array<int, 5> niz;
Now i need to found maximum in that array and to remove it . How to achieve that with class array?
EDIT
so array size cant be modified, so can i swift two elements in array then?
It cannot be done. A std::array has a fixed, compile-time determined number of elements. If you want a container that supports a changing number of elements, you can use for example std::vector.
std::swap.While you cannot remove an element from an array, you can move (by swapping) the max element to the end of the array and keep a dynamic size.
const unsigned int fixed_size=5;
unsigned int dynamic_size = fixed_size;
std::array<int, fixed_size> myArray;
And when you find the max (will let you implement this part), swap it with the last index within the dynamic range. And decrement the dynamic size.
std::swap( myArray[dynamic_size-1], myArray[max_index] );
--dynamic_size;
And this will iterate over the array, excluding the max element.
for( unsigned int i=0; i<dynamic_size; ++i ) printf( "%u: %d\n", i, myArray[i] );