public class BubbleSort : SortBase { public BubbleSort(int num, int[] arr): base(num,arr) { } public override int[] Sort() { int tmp; for (int i = _arr.Length-1; i >= 0; i--) { for (int j = 0; j < i; j++) { if (_arr[j + 1] < _arr[j]) { tmp = _arr[j]; _arr[j] = _arr[j + 1]; _arr[j + 1] = tmp; } } } return _arr; } } public abstract class SortBase { protected int _num; protected int[] _arr; public abstract int[] Sort(); public SortBase(int num, int[] arr) { _num = num; _arr = arr; } public virtual string GetResult() { int[] _result=Sort(); string ss = "结果为:"; for (int i = 0; i < _result.Length; i++) { ss += _result[i].ToString() + " "; } return ss; } }