-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram6.cs
124 lines (93 loc) · 3.55 KB
/
Program6.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Authentication.ExtendedProtection;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ThreadSort
{
internal static class Program6
{
/// <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];
[STAThread]
static void Mainx()
{
//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
}
//Application.Run(new Form5(array));
Form6 form = new Form6(polePRB);
//Application.Run(form);
form.Show();
//form.showData();
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 < polePRB.Length - 1; y++)
{ for (int x = 0; x < polePRB.Length - 1; x++)
{
if (polePRB[x] > polePRB[x + 1]) { }
}
}
}
}
}