2015年11月13日 星期五

C8_4 BobbleSort.cs

using System;
namespace C8_4
{
    public abstract class BobblesSort
    {
        public int length = 0; //數據長度
        ///
        ///泡沫排序演算法
        ///
        ///
        public void DoSort()
        {
            for (int nLast = length - 2; nLast >= 0; nLast--)
            {
                for (int i = 0; i <= nLast; i++)
                {
                    if (Order(i))
                    {
                        Swap(i);
                    }
                }
            }
        }
        ///
        ///交換排序
        ///
        ///
        protected abstract void Swap(int index);
        ///
        ///第一個元素與第二個元素比較大小
        ///
        ///
        ///
        protected abstract bool Order(int index);
    }
}

沒有留言: