Пример #1
0
        static void Main(string[] args)
        {
            ISortingStrategy sortingStrategy = null;

            //Sorting the countyResidents
            List <string> countyResidents = new List <string> {
                "ad", "ac", "ax", "zw"
            };

            sortingStrategy = GetSortingOption(ObjectToSort.CountyResidents);
            sortingStrategy.Sort(countyResidents);

            //Sorting student numbers

            List <int> studentNumbers = new List <int> {
                123, 678, 543, 189
            };

            sortingStrategy = GetSortingOption(ObjectToSort.StudentNumber);
            sortingStrategy.Sort(studentNumbers);


            //Sorting railway passengers
            List <string> railwayPassengers = new List <string> {
                "A21", "Z2", "F3", "G43"
            };

            sortingStrategy = GetSortingOption(ObjectToSort.RailwayPassengers);
            sortingStrategy.Sort(railwayPassengers);
        }
Пример #2
0
        public async Task SortAsync(string sourcePath, string destPath)
        {
            var lines = await File.ReadAllLinesAsync(sourcePath);

            var sortedLines = _sortingStrategy.Sort(lines.Select(x => new Row(x)));
            await File.WriteAllLinesAsync(destPath, sortedLines.Select(x => x.ToString()));
        }
Пример #3
0
        public ICollection <int> Sort(ICollection <int> collection, string algorithm)
        {
            //ISortingStrategy strategy = null;

            // Without Reflection
            // if (algorithm.ToLower() == "selection")
            // {
            //     strategy = new SelectionSorter();
            // }
            // if (algorithm.ToLower() == "quick")
            // {
            //     strategy = new QuickSorter();
            // }
            // if (algorithm.ToLower() == "merge")
            // {
            //     strategy = new MergeSorter();
            // }

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

            ISortingStrategy strategy = (ISortingStrategy)Activator.CreateInstance(sorterType);

            return(strategy.Sort(collection));
        }
Пример #4
0
    public void SortCards(ISortingStrategy sortStrategy)
    {
        List <PlayingCard> playingCardList = new List <PlayingCard>();

        cardList.ForEach(element => playingCardList.Add(element.GetComponent <PlayingCard>()));

        List <PlayingCard> sortedList = sortStrategy.Sort(playingCardList);

        cardList.Clear();
        sortedList.ForEach(element => cardList.Add(element.gameObject));
        RepositionCards();
    }
Пример #5
0
        static void Main(string[] args)
        {
            ISortingStrategy sortingStrategy = null;

            List <int> studentNumbers = new List <int>()
            {
                123, 32, 12, 1
            };

            sortingStrategy = GetSortingOptions(ObjectsToSort.StudentNumber);

            sortingStrategy.Sort(studentNumbers);
        }
Пример #6
0
            public void DisplaySorted(int[] nbs)
            {
                int[] sortedNbs = strategy.Sort(nbs);

                var result = string.Empty;

                foreach (int nb in sortedNbs)
                {
                    result += nb + " ";
                }

                Console.WriteLine(result);
            }
        private async Task SortAndSaveChunk(Chunk chunk, string chunkPath)
        {
            var sw = Stopwatch.StartNew();

            Logger.Debug($"Saving chunk {chunkPath} ({chunk.Items.Count} items)...");

            var sortedChunk = await Task.Run(() => _sortingStrategy.Sort(chunk.Items).ToList()).ConfigureAwait(false);

            Logger.Debug($"Chunk {chunkPath} sorted in {sw.Elapsed}.");

            sw.Restart();
            await File.WriteAllLinesAsync(chunkPath, sortedChunk.Select(x => x.ToString())).ConfigureAwait(false);

            Logger.Debug($"Chunk {chunkPath} saved in {sw.Elapsed}.");
        }
Пример #8
0
        public string Export(List <TcmbCurrencyData> tcmbCurrencyData)
        {
            tcmbCurrencyData = _sortingStrategy.Sort(tcmbCurrencyData);

            using (var memStream = new MemoryStream())
                using (var stream = new StreamReader(memStream))
                    using (var writer = new StreamWriter(memStream))
                        using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
                        {
                            csv.WriteRecords(tcmbCurrencyData);
                            writer.Flush();
                            memStream.Position = 0;
                            string csvAsString = stream.ReadToEnd();
                            return(csvAsString);
                        }
        }
Пример #9
0
 public void Sort(List <int> collection)
 {
     strategy.Sort(collection);
 }
Пример #10
0
 public List <int> Sort(List <int> list)
 {
     return(sortingStrategy.Sort(list));
 }
Пример #11
0
 public IEnumerable <int> SortIntegers(IEnumerable <int> integers)
 {
     return(_sortingStrategy.Sort(integers));
 }
Пример #12
0
 public IEnumerable <T> Sort(IEnumerable <T> source, ISortingStrategy <T> strategy)
 {
     return(strategy.Sort(source));
 }
Пример #13
0
 public void Sort()
 {
     sortingStrategy.Sort(list);
 }
Пример #14
0
 public IReadOnlyList <int> Sort(IEnumerable <int> arrayToSort)
 {
     return(_sortingStrategy
            .Sort(arrayToSort)
            .DeepClone());
 }
Пример #15
0
 private static void Sort(int[] nums, ISortingStrategy sortingStrategy)
 {
     sortingStrategy.Sort(nums);
 }
Пример #16
0
        public List <TShirt> Sort()
        {
            var sortedList = _sortingStrategy.Sort(SortingMethod, TShirts);

            return(sortedList);
        }