I have a huge list of numbers and I'm doing some calculations over each record, e.g:
123 456 789 213 546 789 78 156 489 952 456 789 ......
and after proccessing the list I'm getting the results sequentially (they are not stored in any structure), e.g.
0.156 0.895 0.12 0.145 0.146 0.222 0.123 0.489 ........
Is there some practice, how to save for example top 5 results to fixed array?
1st step:
[0.156]
2nd step:
[0.895 0.156]
5th step:
[0.895 0.156 0.146 0.145 0.12]
nth step:
[0.895 0.489 0.222 0.156 0.146]
It should have complexity O(n), because there is no sorting.