Added Mergesort for Playmovie column sorting for when the number of elements is over 15. ListView currently does not update when the code uses the mergesort portion and not just the insertion sort portion.
This commit is contained in:
parent
d76fd77cfc
commit
7c92c36077
|
@ -202,17 +202,57 @@ namespace BizHawk.MultiClient
|
|||
string columnName = MovieView.Columns[columnToOrder].Text;
|
||||
if (sortedCol.CompareTo(columnName) != 0)
|
||||
sortReverse = false;
|
||||
InsertionSort(MovieList, columnName);
|
||||
MergeSort(MovieList, 0, MovieList.Count, columnName);
|
||||
sortedCol = columnName;
|
||||
sortReverse = !(sortReverse);
|
||||
MovieView.Refresh();
|
||||
}
|
||||
|
||||
private void MergeSort(List<Movie> movieList, int low, int high, string parameter)
|
||||
{
|
||||
int sort = 1;
|
||||
if (sortReverse)
|
||||
sort = -1;
|
||||
|
||||
if (high - low < 15)
|
||||
InsertionSort(movieList, parameter);
|
||||
else
|
||||
{
|
||||
int mid = Convert.ToInt32(((high - low) / 2) + low);
|
||||
MergeSort(movieList, low, mid, parameter);
|
||||
MergeSort(movieList, mid + 1, high, parameter);
|
||||
|
||||
int trackLow = low;
|
||||
int trackHigh = mid+1;
|
||||
List<Movie> sortedList = new List<Movie>();
|
||||
for (int i = low; i <= high ; i++)
|
||||
{
|
||||
|
||||
if ((trackHigh > high) || (movieList[trackLow].CompareTo(movieList[trackHigh], parameter) == sort))
|
||||
{
|
||||
sortedList.Add(movieList[trackLow]);
|
||||
trackLow++;
|
||||
}
|
||||
else
|
||||
{
|
||||
sortedList.Add(movieList[trackHigh]);
|
||||
trackHigh++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = low; i <= high; i++)
|
||||
{
|
||||
movieList[i] = sortedList[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InsertionSort(List<Movie> smallList, string parameter)
|
||||
{
|
||||
int sort = 1;
|
||||
if (sortReverse)
|
||||
sort = -1;
|
||||
|
||||
for (int i = 0; i < smallList.Count; i++)
|
||||
{
|
||||
int smallest = i;
|
||||
|
|
Loading…
Reference in New Issue