Reputation: 1
This specification requires the algorithm to have the lowest possible order of complexity. I am trying to create my own version of LINQ .OrderBy() to achieve this, using a Radix Sort.
IE I am trying to create
var sortedListOfAppointments = listOfAppointments.OrderByDateUsingRadixSort(a => a.AppointmentDateTime);
I currently have a method which accepts any IEnumerable list, and sorts by the stated date field, but at the moment, it only returns the sorted Dates, not the sorted list.
To start with, I have a method which Sorts dates as follows:-
public static IEnumerable<DateTime> SortDatesUsingRadixSort(this IEnumerable<DateTime> dates)
Then I have a method to accept any class, and use the stated field as the field to sort by
public static IEnumerable<DateTime> OrderByDateUsingRadixSort<TSource>(this IEnumerable<TSource> dates, Func<TSource, DateTime> selector) =>
(from date in dates select selector(date)).SortDatesUsingRadixSort();
This works, returns a list of sorted dates, and can be used as follows:-
var sortedDates = listOfAppointments.OrderByDateUsingRadixSort(a => a.AppointmentDateTime);
But I am wanting
var sortedListOfAppointments = listOfAppointments.OrderByDateUsingRadixSort(a => a.AppointmentDateTime);
IE, I am wanting OrderByDateUsingRadixSort to return IEnumerable, but what needs to change in this method to achieve it?
public static IEnumerable<TSource> OrderByDateUsingRadixSort<TSource>(this IEnumerable<TSource> dates, Func<TSource, DateTime> selector) =>
// what needs to change to return the whole list sorted? (from date in dates select selector(date)).SortDatesUsingRadixSort();
I feel like I am missing something small but fundamental in my understanding here.
Sources used to get this far:- https://www.geeksforgeeks.org/how-to-efficiently-sort-a-big-list-dates-in-20s/ https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/how-to-add-custom-methods-for-linq-queries
Upvotes: 0
Views: 49