public ISortStrategy CreateSort(SortAlgorithmEnum sortAlgorithm, SortTypeEnum sortType, IStepCounter stepCounter) { ISortType neededSortType = this.sortTypeFactory.CreateSortType(sortType); switch (sortAlgorithm) { case SortAlgorithmEnum.InsertionSort: { return(new InsertionSort(neededSortType, stepCounter)); } case SortAlgorithmEnum.MergeSort: { return(new MergeSort(neededSortType, stepCounter)); } case SortAlgorithmEnum.QuickSort: { return(new QuickSort(neededSortType, stepCounter)); } case SortAlgorithmEnum.SelectionSort: { return(new SelectionSort(neededSortType, stepCounter)); } default: return(null); } }
public void Sort(string sequence, SortAlgorithmEnum sortAlgorithm, SortTypeEnum sortType) { this.errorMessage = string.Empty; try { this.sortResult = this.sortHandler.Handle(sequence, sortAlgorithm, sortType, new StepCounter()); } catch (ValidationException) { errorMessage = "Not validating sequence"; } this.OnPropertyChanged(string.Empty); }
public ISortResult Handle(string sequence, SortAlgorithmEnum sortAlgorithm, SortTypeEnum sortType, IStepCounter stepCounter) { if (sequence == null) { throw new ArgumentNullException(nameof(sequence)); } if (stepCounter == null) { throw new ArgumentNullException(nameof(sequence)); } IEnumerable <decimal> numbersSequence = this.stringToDecimalCollectionParser.ParseStringToCollection(sequence); ISortResult sortResult = this.sortStrategyFactory.CreateSort(sortAlgorithm, sortType, stepCounter).Sort(numbersSequence); return(sortResult); }