Generic BubbleSort Extension

后端 未结 3 1508
长发绾君心
长发绾君心 2021-01-23 12:49
    public static T[] BubbleSort(this T[] arr) where T : class
    {
        for (int i = 0; i < arr.Length; i++)
        {
            for (int j = 0; j <         


        
3条回答
  •  渐次进展
    2021-01-23 13:24

    A couple of ways you could go about doing this:

    1. Require T to implement IComparable and use the CompareTo method to do comparisons.
    2. Add a second parameter of type IComparer that implements a custom comparison. You would then use this comparer object to do key comparisons.

提交回复
热议问题