Exemple #1
0
        public static void Main(string[] args)
        {
            Helper helper = new Helper();

            SortAlgorithms    algos      = new SortAlgorithms();
            var               watch      = System.Diagnostics.Stopwatch.StartNew();
            List <int>        values     = Enumerable.Range(1, 1500).ToList();
            IEnumerable <int> sortedList = BubbleSort(helper.Shuffle(values));

            watch.Stop();

            int counter   = 0;
            var listItems = sortedList as IList <int> ?? sortedList.ToList();
            int num       = listItems.Count();

            Console.WriteLine("Bubble Sort");

            foreach (int listItem in listItems)
            {
                counter++;
                Console.Write(listItem);
                if (counter < num)
                {
                    Console.Write(",");
                }
            }

            Console.WriteLine();
            Console.WriteLine("Time taken: {0}ms", watch.Elapsed.TotalMilliseconds);
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            SortAlgorithms Algos = new SortAlgorithms();

            IEnumerable <int> sortedList = Algos.BubbleSort(new List <int>()
            {
                100, 2, 4473, 1, 474, 5, 7, 3, 55, 4, 8, 12
            });

            int counter = 0;

            foreach (int listItem in sortedList)
            {
                counter++;
                Console.Write(listItem);
                if (counter < sortedList.Count())
                {
                    Console.Write(",");
                }
            }
            Console.ReadKey();
        }