### C++ Boolean question

Lets say i have the following data of a double array P[ ].
And length of array P[ ] is L. The smallest element in array P[ ] is E.

How can i make use of the data i have and create a Boolean function in the form of :
second_min=(P,L,E)
that finds and print out the 2nd smallest element in the array P[ ] and its corresponding index?
Maybe the Boolean function can include a temporary variable and that temporary variable is used to compare against every element in the array, and when necessary, replacing the temporary variable with the appropriate element.
Have a temp int variable set to the first value of the array and another int variable called index. Loop through the array using a for-loop and check whether array[i] (i is the for-loop counter) is less than the temp var. If it is set temp car to that value and index to i. Continue till the end of the loop. After the loop is over set array[index] to 2000000. Now repeat the same process. After that the temp variable should have the minimum value and index should have the index of the minimum value.

- Cheers!
Topic archived. No new replies allowed.