Skip to content

Commit b2bc06a

Browse files
ClémentClément
authored andcommitted
Working on sorting algos.
1 parent a208d7e commit b2bc06a

2 files changed

Lines changed: 21 additions & 29 deletions

File tree

source/code/projects/Sorting/Sorting/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static void Main(string[] args)
1515
Demo.Run(Sorting<int>.BubbleSort);
1616
Demo.Run(Sorting<char>.BubbleSort);
1717

18-
Demo.Run(Sorting<int>.ShellSort);
18+
Demo.Run(Sorting<int >.ShellSort);
1919
Demo.Run(Sorting<char>.ShellSort);
2020

2121
}

source/code/projects/Sorting/Sorting/Sorting.cs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ static class Sorting<T> where T : IComparable<T>
77
// Helper method
88
private static void Swap(List<T> listP, int lhs, int rhs)
99
{
10-
T temp = listP[lhs];
10+
T current = listP[lhs];
1111
listP[lhs] = listP[rhs];
12-
listP[rhs] = temp;
12+
listP[rhs] = current;
1313
}
1414
public static bool IsSorted(List<T> listP)
1515
{
@@ -121,20 +121,18 @@ public static void ShellSort(List<T> listP)
121121
listP[slot] = current;
122122
}
123123
}
124-
}
125-
126-
127-
128-
129-
// ================================================================================
130-
//
131-
// QuickSort Algorithm
132-
//
133-
// ================================================================================
134-
public static void QuickSort(List<T> listP, int stopOn = 3)
124+
}
125+
126+
// Done with shellSort Algorithm
127+
128+
129+
130+
131+
132+
// QuickSort Algorithm
133+
134+
public static void QuickSort(List<T> listP, int stopOn = 3)
135135
{
136-
Console.WriteLine("-------- QuickSort ---------");
137-
138136
QuickSort(listP, 0, listP.Count - 1, stopOn);
139137
Console.WriteLine("After QuickSort but before it calls InsertionSort");
140138
Displaying<T>.Display(listP);
@@ -198,19 +196,15 @@ public static void QuickSort(List<T> listP, int left, int right, int stopOn)
198196
}
199197
}
200198

201-
// ================================================================================
202-
//
203-
// Selection Sort Algorithm
204-
//
205-
// ================================================================================
199+
// Selection Sort Algorithm
206200
public static void SelectionSort(List<T> listP)
207201
{
208202
SelectionSort(listP, 0, listP.Count - 1);
209203
}
210204

211205
private static void SelectionSort(List<T> listP, int low, int high)
212206
{
213-
T temp;
207+
T current;
214208
for (int i = low; i <= high; ++i)
215209
{
216210
T min = listP[i]; // smallest element so far
@@ -225,20 +219,18 @@ private static void SelectionSort(List<T> listP, int low, int high)
225219

226220
if (i != min_index)
227221
{
228-
temp = listP[i];
222+
current = listP[i];
229223
listP[i] = min;
230-
listP[min_index] = temp;
224+
listP[min_index] = current;
231225
}
232226
}
233227
}
228+
// End of selection sort algorithm
229+
234230

235231

232+
// Merge Sort Algorithm
236233

237-
// ================================================================================
238-
//
239-
// Merge Sort Algorithm
240-
//
241-
// ================================================================================
242234
public static void RecMergeSort(List<T> listP)
243235
{
244236
RecMergeSort(listP, 0, listP.Count);

0 commit comments

Comments
 (0)