Beispiel #1
0
        private IEnumerable <Employee> JoeyOrderByKeepComparer(
            IEnumerable <Employee> employees, ComboComparer comparer)
        {
            //new MyOrderedEnumerable();
            //bubble sort
            var elements = employees.ToList();

            while (elements.Any())
            {
                var minElement = elements[0];
                var index      = 0;
                for (int i = 1; i < elements.Count; i++)
                {
                    var element = elements[i];

                    if (comparer.Compare(element, minElement) < 0)
                    {
                        minElement = element;
                        index      = i;
                    }
                }

                elements.RemoveAt(index);
                yield return(minElement);
            }
        }
Beispiel #2
0
        private IEnumerable <Employee> JoeyOrderByLastNameAndFirstName(
            IEnumerable <Employee> employees,
            ComboComparer comboComparer)
        {
            //bubble sort
            var elements = employees.ToList();

            while (elements.Any())
            {
                var minElement         = elements[0];
                var index              = 0;
                var finalCompareResult = 0;
                for (int i = 1; i < elements.Count; i++)
                {
                    var employee = elements[i];
                    finalCompareResult = comboComparer.Compare(employee, minElement);

                    if (finalCompareResult < 0)
                    {
                        minElement = employee;
                        index      = i;
                    }
                }

                elements.RemoveAt(index);
                yield return(minElement);
            }
        }