-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSorting.cs
More file actions
39 lines (37 loc) · 1.01 KB
/
Copy pathSorting.cs
File metadata and controls
39 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExerciseQuickSort
{
public static class Sorting
{
// variable name
// while/if bloks
public static void QuickSort(int[] array, int leftIndex, int rightIndex)
{
int temp;
int x = array[leftIndex + (rightIndex - leftIndex) / 2];
int i = leftIndex;
int j = rightIndex;
while (i <= j)
{
while (array[i] < x) { i++; }
while (array[j] > x) { j--; }
if (i <= j)
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
i++;
j--;
}
}
if (i < rightIndex)
{ QuickSort(array, i, rightIndex); }
if (leftIndex < j)
{ QuickSort(array, leftIndex, j); }
}
}
}