-
Notifications
You must be signed in to change notification settings - Fork 2
/
Class1.cs
43 lines (41 loc) · 1.02 KB
/
Class1.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace iron_project
{
internal class Class1
{
//перестановка местами двух элементов в массиве
static void Swap(int[] array, int i, int j)
{
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
public static void GnomeSort(int[] inArray)
{
int i = 1;
int j = 2;
while (i < inArray.Length)
{
if (inArray[i - 1] < inArray[i])
{
i = j;
j += 1;
}
else
{
Swap(inArray, i - 1, i);
i -= 1;
if (i == 0)
{
i = j;
j += 1;
}
}
}
}
}
}