sorting - Sort List based on dynamically generated numbers in C++ -
I have a list of objects (in this case "move") that I sort by their calculation evaluation Want to So, I have a list, and a bunch of numbers that are "connected" with one element in the list. Now I want to be the topmost and most lastest person with the first element of the list element with the least connected number. Once the item has been ordered, I can leave the related number. How do i do this
This is my code that looks like (kind've):
list & lt; Move & gt; Moves = board.gatelegalmows (board.turn); (I = moves.begin (); i! = Moves.end (); ++ i) {// ... a = max; // & lt; - Number associated with the current motion}
I would suggest a type. A new vector of the associated value pairs (I suggest to give a vector for more efficient sorting) and make an indicator for its item. Sort the pairs of vectors and then recreate the list from the sorted vector. Since operator & lt;
is defined on std :: pair
, compared with the first item of the pair, and secondly, you will get the proper order.
Example:
Note that you will need the calcocost
function which I have assumed here if your comparison value calculation is time consuming, this approach is a comparative function There is an advantage on making In this way, you only pay the cost to calculate N times instead of 2 * N * log (n).
Comments
Post a Comment