-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram7.cs
More file actions
135 lines (106 loc) · 4.23 KB
/
Program7.cs
File metadata and controls
135 lines (106 loc) · 4.23 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ThreadSort
{
internal static class Program7
{
/// <summary>
/// Hlavní vstupní bod aplikace.
/// </summary>
///int length = 15;
///int[] data = new int[length];
///Random random = new Random();
///int[] array = new int[length];
static int length = 15;
//static int[] data=new int[lenght];
static int[] polePRB = new int[length];
static int[] poleRPBorigin = new int[length];
private static Form6 form, formOrigin;
[STAThread]
static void Main()
{
//Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form3());
//int length = 15;
//int[] data = new int[length];
Random random = new Random();
//int[] array = new int[length];
int pomocA = 1, pomocB = 0;
for (int i = 0; i < length; i++)
{
polePRB[i] = random.Next(101); // Generates a random number between 0 and 100
poleRPBorigin[i] = polePRB[i];
}
//Application.Run(new Form5(array));
form = new Form6(polePRB);
formOrigin = new Form6(poleRPBorigin);
//Application.Run(form);
form.Show();
formOrigin.Show();
form.Location = new System.Drawing.Point(10, 10);
formOrigin.Location = new System.Drawing.Point(500, 10);
System.Threading.Thread.Sleep(10);
int n = polePRB.Length;
bool swapped;
int lastSwapIndex = 0;
do
{
swapped = false;
lastSwapIndex = 0;
for (int i = 1; i < n; i++)
{
{
if (pomocA != pomocB)
{
if (polePRB[i - 1] > polePRB[i])
{
if (polePRB[i - 1] != polePRB[i])
{
// Swap elements
pomocA = polePRB[i - 1]; pomocB = polePRB[i];
int temp = polePRB[i - 1];
polePRB[i - 1] = polePRB[i];
polePRB[i] = temp;
swapped = true;
lastSwapIndex = i ; // nacitani kolik zmen probehlo a nacitase
}
}
}
// Display the progress after each comparison
form.showData(i, n);
System.Threading.Thread.Sleep(10);
}
}
//n--; //poctani puvodni zmenseni pole prochazeni
n = lastSwapIndex; //inicializace kroku podle zmen
}
while (swapped);
BubleSortSimple();
// Display the final sorted data
//form.showData();
System.Threading.Thread.Sleep(10);
form.Show();
}
private static void BubleSortSimple()
{
for (int y = 0; y < poleRPBorigin.Length - 1; y++)
{ for (int x = 0; x < poleRPBorigin.Length - 1; x++)
{
if (poleRPBorigin[x] > poleRPBorigin[x + 1]) {
int pom = poleRPBorigin[x];
poleRPBorigin[x] = poleRPBorigin[x + 1];
poleRPBorigin[x + 1] = pom;
}
formOrigin.showData(x, x + 1);
System.Threading.Thread.Sleep(10);
//pocetPruchodu++; // kolik proslo neni def
}
//pocetVnejsiSmyckou++; //kolik proslo vnejsi casti
}
}
}
}