Skip to content

Commit 6d181a3

Browse files
ClémentClément
authored andcommitted
Merge branch 'main' of github.com:princomp/princomp.github.io
2 parents 8876876 + ad18a15 commit 6d181a3

File tree

3 files changed

+8
-29
lines changed

3 files changed

+8
-29
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ static void Main(string[] args)
1515

1616
Demo.Run(Sorting<int>.ShellSort);
1717
Demo.Run(Sorting<char>.ShellSort);
18-
}
18+
19+
Demo.Run(Sorting<int>.QuickSort);
20+
Demo.Run(Sorting<char>.QuickSort);
21+
}
1922
}

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

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ public static void QuickSort(
241241
)
242242
{
243243
QuickSort(listP, 0, listP.Count - 1, stopOn);
244-
Console.WriteLine(
245-
"After QuickSort but before it calls InsertionSort"
246-
);
247-
Displaying<T>.Display(listP);
248-
Console.WriteLine();
249244
InsertionSort(listP);
250245
}
251246

@@ -255,12 +250,6 @@ private static T median3(
255250
int right
256251
)
257252
{
258-
Console.Write(
259-
"\tIn median3: {0} {1} {2}",
260-
listP[left],
261-
listP[(left + right) / 2],
262-
listP[right]
263-
);
264253
int center = (left + right) / 2;
265254
if (listP[center].CompareTo(listP[left]) < 0)
266255
Swap(listP, left, center);
@@ -284,20 +273,8 @@ int stopOn
284273
return;
285274
else
286275
{
287-
Console.Write("QuickSort({");
288-
for (int j = left; j <= right; j++)
289-
{
290-
Console.Write("{0}", listP[j]);
291-
if (j != right)
292-
Console.Write(", ");
293-
}
294-
Console.Write("}");
295-
Console.WriteLine(", {0}, {1})", left, right);
296-
297-
Console.WriteLine();
276+
Console.WriteLine();
298277
T pivot = median3(listP, left, right);
299-
Console.Write("{0}", new String(' ', left * 4));
300-
Displaying<T>.Display2(listP, left, right + 1);
301278
int i = left; //, j = right;
302279
for (int j = right; i < j; )
303280
{
@@ -311,10 +288,7 @@ int stopOn
311288
break;
312289
}
313290
Swap(listP, i, right); // Move pivot back
314-
Console.Write("{0}", new String(' ', left * 4));
315-
Displaying<T>.Display3(listP, left, right + 1, i);
316-
317-
QuickSort(listP, left, i - 1, stopOn); // sort small partition
291+
QuickSort(listP, left, i - 1, stopOn); // sort small partition
318292
QuickSort(listP, i + 1, right, stopOn); // sort large partition
319293
}
320294
}

source/lectures/misc/sorting.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,5 @@ If the **best case**, if the array is already mostly sorted, then we still need
188188
On **average**, the complexity depends a lot on the sequence, but can be around $O(n^{1.5})$, which is still better than quadratic!
189189

190190
Playing with the gap sequence further can give a **best**, **worst** and **average** performance of $O(n \times (\log(n))^2)$!
191+
192+
## Quick Sort Algorithm

0 commit comments

Comments
 (0)