-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
44 lines (42 loc) · 1.36 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
using System;
namespace sort_insertion
{
class Program
{
static void Main(string[] args)
{
int[] numeros = { 230, 45, 345, 4, 324, 90, 76, 34, 67, 11 };
Console.WriteLine("######## Ordenação com Insertion Sort ########\n");
Console.WriteLine("Array original\n");
foreach (int numero in numeros)
Console.Write($"{numero} ");
Console.WriteLine("\n\nOrdenando o array usando Insertion Short\n");
int[] arrayOrdenado = IntArrayInsertionSort(numeros);
Console.WriteLine("Array Ordenado\n");
foreach (int numero in arrayOrdenado)
Console.Write($"{numero} ");
Console.ReadLine();
}
public static int[] IntArrayInsertionSort(int[] data)
{
int i, j;
int N = data.Length;
for (j = 1; j < N; j++)
{
for (i = j; i > 0 && data[i] < data[i - 1]; i--)
{
TrocarValores(data, i, i - 1);
}
}
return data;
}
public static int[] TrocarValores(int[] arrayDados, int m, int n)
{
int temp;
temp = arrayDados[m];
arrayDados[m] = arrayDados[n];
arrayDados[n] = temp;
return arrayDados;
}
}
}