Having an array of for instance 4 integers how can one determine it's non-zero minimum - in the fastest way ?
The procedure is the same as finding the smallest from an array. On top of that, add a condition to check that the current search is not zero. Note: The change from smallest > priceArr[x] to smallest < priceArr[x] . If your array size is at least 1, you can also set smallest as the first array element.
Unless you keep the minimum value as elements are added to the array, or you keep the array in a sorted order - I see no other solution but to iterate every member to determine the minimum value.
There is no 'fast' way of testing each member.
Generally I suggest do not optimize something unless it actually proves to be slow. The old rule of your program spends 90% of its time in 10% of the code generally holds true. So does the rules that programmers are 99.99% likely to optimize code not in that 10%.
Profile your code - profile your code - profile your code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With