Find the Largest and Smallest and Sort values in array C++
Two functions: findMin() and findMax() have been coded and tested in main().
Please find the code, Arr1.cpp and executable Arr1.exe attached.
The code is explained with comments. You should be able to use the two functions to achieve what you want including sorting of an array.
For sorting, you need to do a little bit more than just finding minimum and maximum from an array. Simply finding the smallest and/or largest does not automatically lend itself to a sorted array.
Specifically, for an array containing positive integers, you need to repeatedly find the largest number (or smallest number) from the array, print it and replace that largest number with a (say ) negative number, so that it doesn't get picked again in the next iteration. Continue doing this for n elements, where n is the length of the array.
This answer includes:
- Plain text
- Cited sources when necessary
- Attached file(s)
Active since 2012