Пример #1
0
        public void MaopaoSiki(List <int> oris, W_SortMode mode = W_SortMode.升序)
        {
            bool swapped = true;

            if (mode == W_SortMode.升序)
            {
                do
                {
                    swapped = false;
                    for (int i = 0; i < oris.Count - 1; i++)
                    {
                        if (oris[i] > oris[i + 1])
                        {
                            U_Exchange.ExchangeFromList(ref oris, i);
                            swapped = true;
                        }
                    }
                }while (swapped);
            }
            else
            {
                do
                {
                    swapped = false;
                    for (int i = 0; i < oris.Count - 1; i++)
                    {
                        if (oris[i] < oris[i + 1])
                        {
                            U_Exchange.ExchangeFromList(ref oris, i);
                            swapped = true;
                        }
                    }
                }while (swapped);
            }
        }
Пример #2
0
        //public List<int> oriList = new List<int> { 9, 3, 2, 4, 3, 656, 9, 5, 62, 846, 32, 54, 1, 65, 6, 97, 6516 };
        //public List<int> tarList = new List<int>();

        public void Maopao(List <int> oris, W_SortMode mode = W_SortMode.升序)
        {
            if (mode == W_SortMode.升序)
            {
                for (int i = 0; i < oris.Count - 1; i++)
                {
                    for (int j = 0; j < oris.Count - 1 - i; j++)
                    {
                        if (oris[j] > oris[j + 1])
                        {
                            U_Exchange.ExchangeFromList(ref oris, j);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < oris.Count - 1; i++)
                {
                    for (int j = 0; j < oris.Count - 1 - i; j++)
                    {
                        if (oris[j] < oris[j + 1])
                        {
                            U_Exchange.ExchangeFromList(ref oris, j);
                        }
                    }
                }
            }
        }
Пример #3
0
        public List <int> Maopao_New(List <int> oris, W_SortMode mode = W_SortMode.升序)
        {
            List <int> tars = U_List.CopyList(oris);

            if (mode == W_SortMode.升序)
            {
                for (int i = 0; i < tars.Count - 1; i++)
                {
                    for (int j = 0; j < tars.Count - 1 - i; j++)
                    {
                        if (tars[j] > tars[j + 1])
                        {
                            U_Exchange.ExchangeFromList(ref tars, j);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < tars.Count - 1; i++)
                {
                    for (int j = 0; j < tars.Count - 1 - i; j++)
                    {
                        if (tars[j] < tars[j + 1])
                        {
                            U_Exchange.ExchangeFromList(ref tars, j);
                        }
                    }
                }
            }
            return(tars);
        }
Пример #4
0
 public void Maopao_OBJ <T>(List <T> oris, Func <T, T, bool> func, W_SortMode mode = W_SortMode.升序)
 {
     if (mode == W_SortMode.升序)
     {
         for (int i = 0; i < oris.Count - 1; i++)
         {
             for (int j = 0; j < oris.Count - 1 - i; j++)
             {
                 if (func(oris[j], oris[j + 1]))
                 {
                     U_Exchange.ExchangeFromList(ref oris, j);
                 }
             }
         }
     }
     else
     {
         for (int i = 0; i < oris.Count - 1; i++)
         {
             for (int j = 0; j < oris.Count - 1 - i; j++)
             {
                 if (!func(oris[j], oris[j + 1]))
                 {
                     U_Exchange.ExchangeFromList(ref oris, j);
                 }
             }
         }
     }
 }