المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Insert object to a sort list in the most efficient way [modified]



C# Programming
07-26-2009, 01:21 PM
I have a list of specific class.
Im doing some simulation and i want to receive in the end the 100 best result.
Lets say i have this class :

class A
{
int j;
int t;

}

and i want to save in some range of j and t the best 100 "A" elements that give me the low math.pow(j/t,2) (100 result of the lowest A that i have).

Right now im insert the result to the list and then sort the list with the Compare method. each time a take the smallest result of the list and then if the current result is more small then then the small one on this. If its is smallest then i insert it into the the array , sort it and then remove the last object and continue.

What is the best way to take a List/Array of sort element and just insert the Current element to it's place in the sorted List/Array and remove that biggest element of the list ? (In C# )

modified on Sunday, July 26, 2009 5:08 AM