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); }
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())); }
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)); }
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(); }
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); }
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}."); }
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); } }
public void Sort(List <int> collection) { strategy.Sort(collection); }
public List <int> Sort(List <int> list) { return(sortingStrategy.Sort(list)); }
public IEnumerable <int> SortIntegers(IEnumerable <int> integers) { return(_sortingStrategy.Sort(integers)); }
public IEnumerable <T> Sort(IEnumerable <T> source, ISortingStrategy <T> strategy) { return(strategy.Sort(source)); }
public void Sort() { sortingStrategy.Sort(list); }
public IReadOnlyList <int> Sort(IEnumerable <int> arrayToSort) { return(_sortingStrategy .Sort(arrayToSort) .DeepClone()); }
private static void Sort(int[] nums, ISortingStrategy sortingStrategy) { sortingStrategy.Sort(nums); }
public List <TShirt> Sort() { var sortedList = _sortingStrategy.Sort(SortingMethod, TShirts); return(sortedList); }