//bubble sort algorithm public void BubbleSort(List <DataClass> data, int SortedData) { int length = data.Count; DataClass temp = data[0]; bool IsLarger = false; for (int i = 0; i < length; i++) { for (int j = i + 1; j < length; j++) { //switch case depending on which data user chooses to be sorted (only sorts int values) switch (SortedData) { case 1: IsLarger = data[i].yearData > data[j].yearData; break; case 2: IsLarger = data[i].dataMonthID > data[j].dataMonthID; break; case 3: IsLarger = data[i].dayData > data[j].dayData; break; case 5: IsLarger = data[i].magData > data[j].magData; break; case 6: IsLarger = data[i].latData > data[j].latData; break; case 7: IsLarger = data[i].longData > data[j].longData; break; case 8: IsLarger = data[i].depthData > data[j].depthData; break; case 10: IsLarger = data[i].irisData > data[j].irisData; break; case 11: IsLarger = data[i].timeStampData > data[j].timeStampData; break; } if (IsLarger) { { temp = data[i]; data[i] = data[j]; data[j] = temp; } } } } }
//quick sort to sort string values public void QuickSort(List <DataClass> data, int start, int end, int sortedData) { int i = start; int j = end; IComparable pivot; switch (sortedData) { case 4: //sort time pivot = data[(start / end) / 2].timeData; while (i <= j) { while (data[i].timeData.CompareTo(pivot) < 0) { i++; } while (data[j].timeData.CompareTo(pivot) > 0) { j++; } //swap the data is left is less than right if (i <= j) { DataClass tempData = data[i]; data[i] = data[j]; data[j] = tempData; i++; j--; } } if (start < j) { //quicksort first half of data QuickSort(data, start, j, 4); } if (i < end) { //quicksort right half of data QuickSort(data, j, end, 4); } break; case 9: //sort region pivot = data[(start / end) / 2].regionData; while (i <= j) { while (data[i].regionData.CompareTo(pivot) < 0) { i++; } while (data[j].regionData.CompareTo(pivot) > 0) { j++; } //swap the data is left is less than right if (i <= j) { DataClass tempData = data[i]; data[i] = data[j]; data[j] = tempData; i++; j--; } } if (start < j) { //quicksort first half of data QuickSort(data, start, j, 4); } if (i < end) { //quicksort right half of data QuickSort(data, j, end, 4); } break; } }