Пример #1
0
        static void Main(string[] args)
        {
            IFileData   file   = Factory.CreateFileData();
            IListSorter sorter = Factory.CreateListSorter();

            // Validate file
            bool fileValidation = file.IsValidFile(args);

            if (fileValidation == false)
            {
                file.ErrorMessage();
                return;
            }

            //Get data from file
            string[] records = file.ReadRecords(args[0]);

            //Create list people
            var peopleList = sorter.CreateList(records);

            //Sort list people
            var sortedPeopleList = sorter.SortByLastName(peopleList);

            //Covert list people to string array
            records = sorter.ConvertModelToString(sortedPeopleList);

            //Display data
            file.DisplayRecords(records);

            //Create file with sorted data
            file.WriteRecords(records);
        }
Пример #2
0
 public OptimizedMergeSorter(IListSorter <T> smallListSorter = null, int smallListSize = 16)
 {
     if (smallListSize <= 0)
     {
         throw new ArgumentException();
     }
     _smallListSorter = smallListSorter ?? new InsertionSorter <T>();
     _smallListSize   = smallListSize;
 }
Пример #3
0
            public ParallelMergeSorter(int?tasksCount = null)
            {
                int tCount = tasksCount ?? Environment.ProcessorCount;

                if (tasksCount < 2)
                {
                    throw new ArgumentException();
                }
                _tasksCount = tCount;
                _sorter     = new OptimizedMergeSorter <T>();
            }
Пример #4
0
        /// <summary>
        /// Starts the tournament
        /// </summary>
        /// <param name="contestantListSorter">An optional implementation of a list sorting algorithm. Defaults to random player shuffeling.</param>
        public void Start(IListSorter contestantListSorter = null)
        {
            if (contestantListSorter == null)
            {
                contestantListSorter = GetListSorter();
            }
            var round1 = Rounds.FirstOrDefault(p => p.RoundNo == 1);

            round1.Start(contestantListSorter, Contestants);
            // Set current contestant and tournament status
            Status = TournamentStatus.Running;
            ResetCounterSet();
        }
Пример #5
0
        /// <summary>
        /// Starts the round and assigns contestants to heats
        /// </summary>
        /// <param name="listSorter">A class providing method for sorting the list by a custom criteria</param>
        /// <param name="contestants">List of contestants to add to the round. If not provided, will look for results in previous round and find those who qualify</param>
        public void Start(IListSorter listSorter, IEnumerable <Contestant> contestants = null)
        {
            // Make sure the list is blank before we start. We may be restarting an earlier ran round
            EnsureListsAreInitialized();
            EraseExistingContestantsAndJudgings();
            // (re)generate list of contestants
            if (contestants == null)
            {
                if (QualifiesFromRound == null)
                {
                    throw new ArgumentException("Either contestants must be specified, or QualifiesFromRound must be set");
                }
                contestants = QualifiesFromRound.GetContestantEntriesScoreSorted().Select(p => p.Contestant);
            }

            // Cut out the number of playes who are to qualify
            if (MaxContestants > 0)
            {
                contestants = contestants.Take(MaxContestants);
            }
            int count = MaxContestants;

            if (count == 0)
            {
                count = Int32.MaxValue;
            }
            count = Math.Min(contestants.Count(), count);

            // Define heats
            List <Contestant> contestantList = contestants.ToList();

            if (ContestantsPerHeat == 0)
            {
                ContestantsPerHeat = contestantList.Count;
            }

            listSorter.Sort(contestantList); // Sort list by some custom criteria
            for (int i = 0; i < count; i++)
            {
                var rc = AddContesant(contestantList[i]);
                rc.HeatNo  = i / ContestantsPerHeat + 1;
                rc.Ordinal = i + 1;
            }
            Status = TournamentStatus.Running;
        }