find largest 3 element in array

plz tell me how to find first 3 largest element in array in c++ plz answer me and
answer should not difficult because i am new in programming plz help me God bless you
please review this thread:
http://www.cplusplus.com/forum/beginner/1/

Don't be a beggar. Please try coding something first and if it's not working we can look further into assisting you with your issue.
The obvious solution would be to have 3 variables to store largest values.
Looping through each element and assigning the new values as they are found.

Here is some pseudo code:

Say we have 1 2 3 4 5 6 7 8 9 10

largest1 = 1; (element 0)
largest2 = 2; (element 1)
largest3 = 3; (element 2)

Loop from index 3 -> n - 1

if data[i] >= largest3 (>= if you have repeated values you didn't mention)

largest1 = largest2;
largest2 = largest3;
largest3 = data[i]; (element i)

Topic archived. No new replies allowed.