Add project files.
This commit is contained in:
44
Sortering/Sort.cs
Normal file
44
Sortering/Sort.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
namespace Sortering
|
||||
{
|
||||
public static class Sort
|
||||
{
|
||||
public static void InsertionSort(int[] array)
|
||||
{
|
||||
int i, n;
|
||||
int length = array.Length;
|
||||
int temp;
|
||||
|
||||
if (length < 2) return;
|
||||
|
||||
for (n=1; n<length; n++)
|
||||
{
|
||||
temp = array[n];
|
||||
i = n - 1;
|
||||
|
||||
while (i >= 0 && array[i] > temp)
|
||||
{
|
||||
array[i+1] = array[i];
|
||||
i--;
|
||||
}
|
||||
|
||||
array[i+1] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
public static void BubbleSort(int[] array)
|
||||
{
|
||||
for (int m = array.Length-1; m > 0; m--)
|
||||
{
|
||||
for (int n = 0; n<m; n++)
|
||||
{
|
||||
if (array[n] > array[n + 1])
|
||||
{
|
||||
int temp = array[n];
|
||||
array[n] = array[n+1];
|
||||
array[n+1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user