-
Notifications
You must be signed in to change notification settings - Fork 0
/
quick-sort.cs
61 lines (59 loc) · 1.46 KB
/
quick-sort.cs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
namespace Base
{
class Program
{
public static void Sort(ref int[] array, int b, int e)
{
int l = b;
int r = e;
int p = array[(l + r) / 2];
while(l <= r)
{
while(array[l] < p)
{
l ++;
}
while(array[r] > p)
{
r --;
}
if(l <= r)
{
if(l < r)
{
array[l] = array[l] + array[r];
array[r] = array[l] - array[r];
array[l] = array[l] - array[r];
}
l ++;
r --;
}
}
if(b < r)
{
Sort(ref array, b, r);
}
if(e > l)
{
Sort(ref array, l, e);
}
}
public static void Main()
{
string[] w = Console.ReadLine().Split(" ");
int[] a = new int[w.Length];
for(int i = 0; i < w.Length; i ++)
{
a[i] = Convert.ToInt32(w[i]);
}
Sort(ref a, 0, a.Length - 1);
foreach(int i in a)
{
Console.Write(i);
Console.Write(" ");
}
Console.ReadLine();
}
}
}