Monday, March 2, 2015

Sorting Algorithms

http://www.codeproject.com/Articles/79040/Sorting-Algorithms-Codes-in-C-NET






 static void Main(string[] args)
        {
            List<int> objList = new List<int> { 2, 6, 3, 7, 1, 8, };
         
            foreach (int a in objList)
            {
                Console.WriteLine("Before sort : {0}",a);
            }
            Console.WriteLine(" ");
            List<int> objSortedList = bubblesort(objList);
            foreach (int a in objSortedList)
            {
                Console.WriteLine("After sort : {0}", a);
             
            }
            Console.ReadLine();
        }
        public static List<int> bubblesort(List<int> a)
        {
            int temp;
            // foreach(int i in a)
            for (int i = 1; i <= a.Count; i++)
                for (int j = 0; j < a.Count - i; j++)
                    if (a[j] > a[j + 1])
                    {
                        temp = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = temp;
                    }
            return a;
        }


































































































No comments:

Post a Comment

AZ-204

 42,43,44,45,46,54,55,56,57,70, 71, 80, 98,99,100,108, 104, 105, 106, 192, 193, 194, 209, 206, 207, 210, 325,326,327,329,345,346,364,373,351...