Created
April 3, 2020 22:24
-
-
Save asa55/a5b0721040f0ae74d6127faee87caf76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How do you find the largest and smallest number in an unsorted integer array? | |
#include <iostream> | |
#include <vector> | |
auto main() -> int | |
{ | |
std::vector<int> unsorted_arr = { 9, 2, 3, 4, 5, 10, 7, 8, 1, 6 }; | |
int* max_index = &unsorted_arr[0]; | |
int* min_index = &unsorted_arr[0]; | |
for ( int i = 0; i < 10; ++i ) | |
if ( unsorted_arr[ i ] > *max_index ) max_index = &unsorted_arr[ i ]; | |
for ( int i = 0; i < 10; ++i ) | |
if ( unsorted_arr[ i ] < *min_index ) min_index = &unsorted_arr[ i ]; | |
std::cout << "MAX: " << *max_index << std::endl; | |
std::cout << "MIN: " << *min_index << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment