-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
59 lines (45 loc) · 1.49 KB
/
Program.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
using System;
using System.Collections.Generic;
namespace inf04
{
internal static class Program
{
private const int NumberOfElements = 10;
private static int[] _integerArray = new int[NumberOfElements];
public static void Main(string[] args)
{
Console.WriteLine("Wczytywanie z klawiatury: ");
for (var i = 0; i < NumberOfElements; i++)
{
var add = int.Parse(Console.ReadLine());
_integerArray[i] = add;
}
SelectionSort(_integerArray);
Console.WriteLine("Po sortowaniu: ");
foreach (var item in _integerArray)
{
Console.WriteLine(item);
}
Console.WriteLine("Najwieksza liczba w tablicy: ");
Console.WriteLine(GetHighestNumber(_integerArray));
}
private static int[] SelectionSort(int[] list)
{
for (var i = 0; i < NumberOfElements - 1 ; i++)
{
var max = i;
for (var j = i + 1 ; j < NumberOfElements; j++)
{
if (list[max] < list[j])
max = j;
}
(list[max], list[i]) = (list[i], list[max]);
}
return list;
}
private static int GetHighestNumber(IList<int> list)
{
return list[0];
}
}
}