changed insert sort

This commit is contained in:
ikpil 2023-07-25 15:44:57 +09:00
parent f78b377d26
commit 7f10d5814d
2 changed files with 24 additions and 1 deletions

View File

@ -5,6 +5,28 @@ namespace DotRecast.Core
{
public static class CollectionExtensions
{
/// Sorts the given data in-place using insertion sort.
///
/// @param data The data to sort
/// @param dataLength The number of elements in @p data
public static void InsertSort(this int[] data)
{
for (int valueIndex = 1; valueIndex < data.Length; valueIndex++)
{
int value = data[valueIndex];
int insertionIndex;
for (insertionIndex = valueIndex - 1; insertionIndex >= 0 && data[insertionIndex] > value; insertionIndex--)
{
// Shift over values
data[insertionIndex + 1] = data[insertionIndex];
}
// Insert the value in sorted order.
data[insertionIndex + 1] = value;
}
}
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
{
foreach (var item in collection)

View File

@ -319,7 +319,8 @@ namespace DotRecast.Recast
}
}
Array.Sort(neighborAreas);
//Array.Sort(neighborAreas);
neighborAreas.InsertSort();
areas[spanIndex] = neighborAreas[4];
}
}