-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortings.txt
94 lines (80 loc) · 1.54 KB
/
sortings.txt
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# include <stdio.h>
# include <stdlib.h>
void print(int a[], int);
void main()
{
int a[] = {5, 10, 3, 8, 4, 7, 2, 1, 6, 9};
int n = 10;
print(a, n);
//sort
print(a, n);
}
void print(int a[], int n)
{
for (int i = 0; i < n; i++)
{
printf("%d ", a[i]);
}
printf("\n");
}
/*
bubble sort
int temp;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (a[j+1] < a[j])
{
temp = a[j+1];
a[j+1] = a[j];
a[j] = temp;
}
}
}
*/
/*
selection sort
int pos, temp;
for (int i = 0; i < n - 1; i++)
{
pos = i;
for (int j = i + 1; j < n; j++)
{
if (a[j] < a[pos])
pos = j;
}
temp = a[pos];
a[pos] = a[i];
a[i] = temp;
}
*/
/*
insertion sort
int curr, j;
for (int i = 1; i < n; i++)
{
curr = a[i];
for (j = i - 1; j >= 0 && a[j] > curr; j--)
{
a[j+1] = a[j];
}
a[j+1] = curr;
}
*/
/*
shell sort
int i, j, gap, curr;
for (gap = n / 2; gap > 0; gap /= 2)
{
for (i = gap; i < n; i++)
{
curr = a[i];
for (j = i; j - gap >= 0 && a[j - gap] > curr; j-= gap)
{
a[j] = a[j-gap];
}
a[j] = curr;
}
}
*/