private int[] GetPositionsFromDriverIndex() { int[] resultsByDriverIndex = new int[Data.NumberOfDrivers]; DriverTimingDataElement[] driverTopSpeeds = new DriverTimingDataElement[Data.NumberOfDrivers]; for (int driverIndex = 0; driverIndex < Data.NumberOfDrivers; driverIndex++) { driverTopSpeeds[driverIndex].driverIndex = driverIndex; driverTopSpeeds[driverIndex].value = TopSpeeds[driverIndex]; } Functions.QuickSort <DriverTimingDataElement>(ref driverTopSpeeds, 0, driverTopSpeeds.Length - 1, (a, b) => { return(a.value < b.value); }); for (int position = 0; position < Data.NumberOfDrivers; position++) { resultsByDriverIndex[driverTopSpeeds[position].driverIndex] = position; } return(resultsByDriverIndex); }
/// <summary> /// Calculates and returns an array of positions, indexed by the driver's position in the session. /// </summary> /// <returns></returns> private int[] GetPositionsFromDriverIndex() { int[] resultsByDriverIndex = new int[Data.NumberOfDrivers]; DriverTimingDataElement[] fastestLaps = new DriverTimingDataElement[Data.NumberOfDrivers]; for (int driverIndex = 0; driverIndex < Data.NumberOfDrivers; driverIndex++) { fastestLaps[driverIndex].driverIndex = driverIndex; fastestLaps[driverIndex].value = GetFastestLapFromSessionData(DriverWeekendStints[driverIndex]); } Functions.QuickSort <DriverTimingDataElement>(ref fastestLaps, 0, fastestLaps.Length - 1, (a, b) => { return(a.value > b.value); }); for (int position = 0; position < Data.NumberOfDrivers; position++) { resultsByDriverIndex[fastestLaps[position].driverIndex] = position; } return(resultsByDriverIndex); }