Untitled
unknown
c_cpp
10 months ago
709 B
2
Indexable
int findSmallestIndex( const std::vector< int >& vec ) { int result = 0; int minElement = vec[ 0 ]; for( int i = 1; i < vec.size(); ++i ) { if( vec[ i ] < minElement ) { minElement = vec[ i ]; result = i; } } return result; } int beforeSmallest( const std::vector< int >& vec ) { int result = 0; int smallestIndex = findSmallestIndex( vec ); result = vec[ smallestIndex - 1 ]; return result; } int afterSmallest( const std::vector< int >& vec ) { int result = 0; int smallestIndex = findSmallestIndex( vec ); result = vec[ smallestIndex + 1 ]; return result; }
Editor is loading...
Leave a Comment