예제 #1
0
        public ICollection <int> Sort
            (ICollection <int> collection, string algorithm)
        {
            //var allTypes = Assembly
            //    .GetExecutingAssembly()
            //    .GetTypes()
            //    .ToList(); // all classes in the assembly

            var sorterType = Assembly
                             .GetExecutingAssembly()
                             .GetTypes()
                             .Where(t => typeof(ISortingStrategyPattern).IsAssignableFrom(t) && t.IsClass)
                             .FirstOrDefault(t => t.Name.ToLower().Contains(algorithm));


            ISortingStrategyPattern pattern = (ISortingStrategyPattern)Activator.CreateInstance(sorterType);

            return(pattern.Sort(collection));
        }
        public ICollection <int> Sort
            (ICollection <int> collection, string algorithm)
        {
            ISortingStrategyPattern pattern = null;

            if (algorithm.ToLower() == "selection")
            {
                pattern = new SelectionSorter();
            }
            if (algorithm.ToLower() == "quick")
            {
                pattern = new QuickSorter();
            }
            if (algorithm.ToLower() == "merge") // modification added
            {
                pattern = new MergeSorter();
            }

            return(pattern.Sort(collection));
        }