超越期望
海滨的小屋

想要对一个string数组排序
原来的数组是这样{"bb","bb","fff","a","ffff","c","dd","f","dd","e","dd"}
现在对这个数组进行排序,排序的规则是只出现一次的排在前面,出现2次及2次
以上的排在后面,那么就上面的数组排序后想要的结果就是
{"a","c","e","f","bb","bb","dd","dd","dd","fff","ffff"}

    protected void Button1_Click(object sender, EventArgs e)
    
{
        
string[] arr = "bb""bb","fff","a","ffff","c""dd""f""dd""e""dd" };
        SortByCount(arr);
    }

    
    
public void SortByCount(string[] source)
    
{       
        Comparison
<string> com = new Comparison<String>(function);
        Array.Sort
<string>(source, com);        
    }


    
int function(string s1, string s2)
    
{
        
return s1.Length - s2.Length == 0 ? string.Compare(s1, s2) : s1.Length - s2.Length;                
    }

posted on 2008-07-11 14:49  Savior(海滨)  阅读(5767)  评论(0编辑  收藏  举报