The task of searching for orders - page 12

 
Dmitry Fedoseev:
Know what you are doing. At first you seem to have just decided to put together a class with everything you have, to find some universal approach when dealing with warrants. But you are solving a very specific task.
In the first post it says look for two maximum orders by type, look for two minimum orders by type, look for the last two orders by type and look for the first two orders by type.
 
Vladimir Pastushak:
Yes, because only one cycle fills the structure, and after that you have to start the cycle again to find the required element, if the number of elements you need is more than 1, the number of cycles will be more than 1

Yes. Whichever way you look at it. Whichever way you look at it, that's the way it will be.

If we need to find only two orders with the highest price, we will have two loops, and if we need 3, we will have 3 loops. Of course, we don't have to sort everything.

 
Dmitry Fedoseev:

Yes. Whichever way you look at it. Whichever way you look at it, that's the way it will be.

If we need to find only two orders with the highest price, we will have two loops, and if we need 3, we will have 3 loops. Of course, we don't have to sort everything.

I have made everything into one cycle...
 
Vladimir Pastushak:
In the first post it says , find two maximum orders by type , find two minimum orders by type , find two last orders by type and find two first orders by type.
As we usually search for a maximum, only two variables. First, we check with one variable and if it is bigger, we transfer the value from it to the second variable and then we add the new value to it. If it is not more, then we compare it with the second variable. It's like the usual search for the maximum value, only a little bit more complicated.
 
Vladimir Pastushak:
I did everything in one cycle...
In one cycle. But the number of actions is like two loops. There are two checks on one pass.
 
Dmitry Fedoseev:
This is the usual maximum search, we only need two variables. First, we check with one variable; if it is larger, we flip the value from it to the second variable and not to the new value. If it is not more, then we compare it with the second one. It's like a usual search for the maximal value, only a bit more complicated.

I know how to do that...

The question is another...

We are now using a class member of the Buy.Price_Max.Price type that has several components

Buy all about the buy order

Price_Max all about the maximum order

Price Price is the price of the maximal order

 
Vladimir Pastushak:

I know how to do that...

The question is another...

our code now uses a member of the Buy.Price_Max.Price class which has all the following components

Buy all about the buy order

Price_Max all about the max order

Price price of the maximal order

What is the question? What to store the values in is not that important.
 
Dmitry Fedoseev:
What is the question? What to store the values in is not so crucial.
The question is about finding the fastest and most stable method ...
 
Vladimir Pastushak:
The question is to find the fastest and most stable method ...
You've already found the fastest one. One cycle, two checks. But only to remember one ticket. After the cycle, select the order on the ticket and take all its properties.
 
Dmitry Fedoseev:
That's because they've already found the fastest one. One cycle, two checks. But only remember one ticket. After the cycle, select the order on the ticket and take all its properties.
Yeah, thought maybe someone knows better ....