title: Find n largest elements from an array
body: <p>I have an array </p>
  
  <pre><code>A[4]={4,5,9,1}
  </code></pre>
  
  <p>I need it would give the first 3 top elements like 9,5,4</p>
  
  <p>I know how  to find the max element but how to find the 2nd and 3rd max?</p>
  
  <p>i.e if </p>
  
  <pre><code>max=A[0]
  for(i=1;i&lt;4;i++)
  {
    if (A[i]&gt;max)
    {
      max=A[i];
      location=i+1;
    }
  }
  </code></pre>
  
  <p>actually sorting will not be suitable for my application because,</p>
  
  <p>the position number is also important for me i.e. I have to know in which positions the first 3 maximum is occurring, here it is in 0th,1th and 2nd position...so I am thinking of a logic</p>
  
  <p>that after getting the max value if I could put 0 at that location and could apply the same steps for that new array i.e.{4,5,0,1}</p>
  
  <p>But I am bit confused how to put my logic in code</p>