Click here to Skip to main content
15,914,246 members
Home / Discussions / C#
   

C#

 
AnswerRe: Unicode Pin
Manas Bhardwaj26-Jul-09 4:16
professionalManas Bhardwaj26-Jul-09 4:16 
AnswerRe: Unicode Pin
harold aptroot26-Jul-09 4:48
harold aptroot26-Jul-09 4:48 
QuestionC# datagridview display Question Pin
spankyleo12326-Jul-09 3:26
spankyleo12326-Jul-09 3:26 
AnswerRe: C# datagridview display Question Pin
Henry Minute26-Jul-09 3:45
Henry Minute26-Jul-09 3:45 
GeneralRe: C# datagridview display Question Pin
spankyleo12326-Jul-09 4:29
spankyleo12326-Jul-09 4:29 
GeneralRe: C# datagridview display Question Pin
Henry Minute26-Jul-09 4:46
Henry Minute26-Jul-09 4:46 
QuestionTaking screenshots from DirectX Games Pin
SimpleData26-Jul-09 2:55
SimpleData26-Jul-09 2:55 
QuestionInsert Obejct to sorted list Pin
bonzaiholding26-Jul-09 2:44
bonzaiholding26-Jul-09 2:44 
How can i insert to list/array an object to the right place by some comparison function and in the end of the process to get back the best 100 object?

for example if i have this code:


<br />
 class Example : IComparable<br />
    {<br />
        //Var's and Prop's of class<br />
        public double num1;<br />
        public double num2;<br />
        public double GetIt<br />
        {<br />
            get<br />
            {<br />
                return num1 * num2;<br />
            }<br />
        }<br />
<br />
        //Some function the return value based on var's of class<br />
        public double SomeValue()<br />
        {<br />
            double result = this.num1 * this.num2 - this.num1 / (this.num2 + 1);<br />
            return result;<br />
        }<br />
<br />
        //Compare function between 2 Example's<br />
        #region IComparable Members<br />
<br />
        public int CompareTo(object obj)<br />
        {<br />
            Example e1 = (Example)obj;<br />
            int res = (this.SomeValue() - e1.SomeValue()) > 0 ? 1 : -1;<br />
            return res;<br />
        }<br />
<br />
<br />
        #endregion<br />
    }<br />
<br />
    //Class that want to find the best 100 Examples<br />
    class UsingExample<br />
    {<br />
        public List<Example> m_List;<br />
<br />
        public UsingExample()<br />
        {<br />
            m_List = new List<Example>();<br />
            for (int num1 = 1; num1 <= 100; num1++)<br />
                for (int num2 = 1; num2 <= 100; num2++)<br />
                {<br />
                    //Create the current Example<br />
                    Example e1 = new Example();<br />
                    e1.num1 = num1;<br />
                    e1.num2 = num2;<br />
                    //Insert into list and then sort (By Example.CompareTo)<br />
                    m_List.Add(e1);<br />
                    m_List.Sort();<br />
<br />
                    //I want just 100 result on the list and not 10,000^2<br />
                    if (m_List.Count > 100)<br />
                        m_List.RemoveAt(100);<br />
                }<br />
<br />
            //In the end i will have the best result 100 result<br />
<br />
        }<br />
        public Example this[int num]<br />
        {<br />
            get { return this.m_List[num]; }<br />
        }<br />
<br />
<br />
    }<br />
<br />


The problem is that every time i need to sort all the list. What is the best way to do it in C# by this process:
1. Insert an object to Sorted Array/List in the right place.
2. If the Current Instance of an object is Smaller then the biggest object in the 100 small object list (by Some IComparable functions):
2.1 Remove the biggest object from the list.

by This process i want to remaine with the smallest object in 100 list.
what is the best way to do it because i don't want to sort the Array every iteration if the Array/List is allready sorted.
AnswerRe: Insert Obejct to sorted list [modified] Pin
PIEBALDconsult26-Jul-09 4:39
mvePIEBALDconsult26-Jul-09 4:39 
GeneralRe: Insert Obejct to sorted list Pin
bonzaiholding26-Jul-09 6:15
bonzaiholding26-Jul-09 6:15 
GeneralRe: Insert Obejct to sorted list Pin
PIEBALDconsult26-Jul-09 6:26
mvePIEBALDconsult26-Jul-09 6:26 
GeneralRe: Insert Obejct to sorted list [modified] Pin
bonzaiholding26-Jul-09 6:31
bonzaiholding26-Jul-09 6:31 
GeneralRe: Insert Obejct to sorted list Pin
PIEBALDconsult26-Jul-09 6:51
mvePIEBALDconsult26-Jul-09 6:51 
GeneralRe: Insert Obejct to sorted list Pin
bonzaiholding26-Jul-09 20:39
bonzaiholding26-Jul-09 20:39 
GeneralRe: Insert Obejct to sorted list Pin
Luc Pattyn26-Jul-09 11:32
sitebuilderLuc Pattyn26-Jul-09 11:32 
GeneralRe: Insert Obejct to sorted list Pin
PIEBALDconsult26-Jul-09 14:49
mvePIEBALDconsult26-Jul-09 14:49 
AnswerRe: Insert Obejct to sorted list Pin
Martijn Boeker26-Jul-09 21:55
Martijn Boeker26-Jul-09 21:55 
GeneralRe: Insert Obejct to sorted list Pin
bonzaiholding26-Jul-09 22:40
bonzaiholding26-Jul-09 22:40 
GeneralRe: Insert Obejct to sorted list Pin
Martijn Boeker27-Jul-09 9:19
Martijn Boeker27-Jul-09 9:19 
Generalreality check Pin
Luc Pattyn27-Jul-09 10:47
sitebuilderLuc Pattyn27-Jul-09 10:47 
QuestionHow do I add the floating Toolbar with TabPage like "Might and Magic V Map Editor" Pin
akira3225-Jul-09 22:46
akira3225-Jul-09 22:46 
AnswerRe: How do I add the floating Toolbar with TabPage like "Might and Magic V Map Editor" Pin
Abhijit Jana26-Jul-09 3:12
professionalAbhijit Jana26-Jul-09 3:12 
GeneralRe: How do I add the floating Toolbar with TabPage like "Might and Magic V Map Editor" Pin
akira3227-Jul-09 6:45
akira3227-Jul-09 6:45 
QuestionInsert object to a sort list in the most efficient way Pin
bonzaiholding25-Jul-09 22:39
bonzaiholding25-Jul-09 22:39 
AnswerRe: Insert object to a sort list in the most efficient way Pin
PIEBALDconsult26-Jul-09 4:53
mvePIEBALDconsult26-Jul-09 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.