Question

I want to find best 3 value from an array where i got array from input.how many element will be in the array will also input from user. then randomly array will input. but how can i find best three element from this array. array = (12, 20, 15, 28, 35). i want to find 35 28 20. what is the way. want some example of code.

Was it helpful?

Solution

Begin
    Create storage for three elements of the array
    Load the storage area with the first three elements of the array
    Iterate through the array, starting with the fourth element:
        If the current element in the array is larger than any of the three elements in the storage:
            Replace the smallest of the three elements with that element
        End
    End
End
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top