-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort.cs
More file actions
69 lines (67 loc) · 1.36 KB
/
Sort.cs
File metadata and controls
69 lines (67 loc) · 1.36 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
namespace CSharpSorting
{
public static class Sort
{
//By Erik Boeson
public static int[] bubble(int[] array)
{
//loop through the array until sorted
for (int i = 0; i < array.Length; i++)
{
//loop through the array once
for (int j = 1; j < array.Length; j++)
{
//is the first value of two larger?
//if so, move it up
if (array[j - 1] > array[j])
{
//store second value and replace it with the first
int temp = array[j];
array[j] = array[j - 1];
//make first value the second value
array[j - 1] = temp;
}
}
}
return array;
}
//By Erik Boeson
public static int[] selection(int[] array)
{
for (int i = array.Length - 1; i > 0; i--)
{
int high = array[0];
int index = 0;
for (int j = 0; j < i; j++)
{
if (array[j] > high)
{
high = array[j];
index = j;
}
}
}
return array;
}
//Written by Dieter Brehm
public static int[] insertion(int[] array)
{
//Loop through the array until sorted
for (int i = 1; i < array.Length; i++)
{
int index = array[i];
int j = i;
//The two conditions of the insertion sort.
//imcrement then decrement
while ((j > 0) && (array[j - 1] > index))
{
array[j] = array[j - 1];
j = j - 1;
}
array[j] = index;
}
return array;
}
}
}