-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (48 loc) · 1.24 KB
/
Program.cs
File metadata and controls
50 lines (48 loc) · 1.24 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
40
41
42
43
44
45
46
47
48
49
50
using System;
namespace test
{
class Program
{
static void Main(string[] args)
{
int[] a;
int n = 100;
a = CreateArray(n);
SelectionSort(a, a.Length);
PrintArray(a);
}
static void PrintArray(int[] a)
{
for (int i = 0; i < a.Length; i++)
Console.Write(a[i].ToString() + " ");
Console.WriteLine("");
}
static int[] CreateArray(int n)
{
int[] a = new int[n];
Random r = new Random();
for (int i = 0; i < n; i++)
a[i] = r.Next(10,10000);
return a;
}
public static void SelectionSort(int[] a, int n)
{
for (int i = 0; i < n - 1; i++)
{
int min = i;
for (int j = i + 1; j < n; j++)
{
if (a[j] < a[min])
min = j;
}
Swap(ref a[min], ref a[i]);
}
}
static void Swap(ref int a, ref int b)
{
int temp = a;
a = b;
b = temp;
}
}
}