Beispiel #1
0
 private IList <T> Mergesort(IList <T> list, int left, int right)
 {
     if (left < right)
     {
         int middle = left + (right - left) / 2;
         Mergesort(list, left, middle);
         Mergesort(list, middle + 1, right);
         Merge(list, left, middle, right);
         Debug.Write("\n Next Pass:- ");
         DebugDiaglostics <T> .Print(list);
     }
     return(list);
 }
Beispiel #2
0
        public IList <T> Sort(IList <T> list)
        {
            Debug.WriteLine("Starting Bubble sort.");
            List <T> _list = new List <T>(list.Count);

            for (int pass = 0; pass < list.Count; pass++)
            {
                for (int index = pass; index < list.Count; index++)
                {
                    if (list[index].CompareTo(list[pass]) < 0)
                    {
                        Utility <T> .Swape(list, pass, index);
                    }
                }

                System.Diagnostics.Debug.Write("\n Pass { " + pass + " }");
                DebugDiaglostics <T> .Print(list);
            }
            Debug.WriteLine("\n End of Bubble sort.");
            return(list);
        }
Beispiel #3
0
        public IList <T> Sort(IList <T> list)
        {
            Debug.WriteLine("Starting Selection sort.");
            for (int currIndex = 0; currIndex < list.Count; currIndex++)
            {
                int smallIndex = currIndex;
                for (int index = currIndex + 1; index < list.Count; index++)
                {
                    if (list[smallIndex].CompareTo(list[index]) > 0)
                    {
                        smallIndex = index;
                    }
                }

                Utility <T> .Swape(list, currIndex, smallIndex);

                Debug.Write("\n Pass { " + currIndex + " }");
                DebugDiaglostics <T> .Print(list);
            }
            Debug.WriteLine("\nEnd of Selection sort. \n");

            return(list);
        }