Skip to content

Commit 41ef9fc

Browse files
committed
Fixed #14
1 parent 176e312 commit 41ef9fc

9 files changed

Lines changed: 440 additions & 58 deletions

File tree

modules/BubbleSort/U_Sort.Bubble.pas

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ interface
55
uses U_SortClass, U_SortInterface, FMX.Layouts, System.SysUtils;
66

77
type
8-
TSortBubble = class(TSortClass, ISortInterface<TLayout>)
8+
TSortBubble = class(TSortClass, ISortInterface)
99
private
10-
procedure sort(layout01 : TLayout);
10+
procedure algoritmo(); Override;
1111

1212
public
1313
constructor Create(layout01 : TLayout);
14+
15+
procedure sort();
16+
1417
end;
1518

1619
implementation
@@ -20,12 +23,15 @@ implementation
2023
constructor TSortBubble.Create(layout01: TLayout);
2124
begin
2225
inherited Create(layout01);
23-
sleep(2000);
24-
sort(layout01);
2526

2627
end;
2728

28-
procedure TSortBubble.sort(layout01: TLayout);
29+
procedure TSortBubble.sort;
30+
begin
31+
inherited sort();
32+
end;
33+
34+
procedure TSortBubble.algoritmo();
2935
var
3036
i, j : Integer;
3137

modules/CombSort/U_Sort.Comb.pas

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ interface
55
uses U_SortClass, U_SortInterface, FMX.Layouts, System.SysUtils;
66

77
type
8-
TSortComb = class(TSortClass, ISortInterface<TLayout>)
9-
private
10-
procedure sort(layout01 : TLayout);
11-
8+
TSortComb = class(TSortClass, ISortInterface)
129
public
1310
constructor Create(layout01 : TLayout);
11+
12+
procedure sort(); Override;
13+
1414
end;
1515

1616
implementation
@@ -20,12 +20,10 @@ implementation
2020
constructor TSortComb.Create(layout01: TLayout);
2121
begin
2222
inherited Create(layout01);
23-
sleep(2000);
24-
sort(layout01);
2523

2624
end;
2725

28-
procedure TSortComb.sort(layout01: TLayout);
26+
procedure TSortComb.sort();
2927
var
3028
i, gap, tamanho : Integer;
3129

modules/InsertionSort/U_Sort.Insertion.pas

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ interface
55
uses U_SortClass, U_SortInterface, FMX.Layouts, System.SysUtils;
66

77
type
8-
TSortInsertion = class(TSortClass, ISortInterface<TLayout>)
9-
private
10-
procedure sort(layout01 : TLayout);
11-
8+
TSortInsertion = class(TSortClass, ISortInterface)
129
public
1310
constructor Create(layout01 : TLayout);
11+
12+
procedure sort(); Override;
13+
1414
end;
1515

1616
implementation
@@ -20,12 +20,10 @@ implementation
2020
constructor TSortInsertion.Create(layout01: TLayout);
2121
begin
2222
inherited Create(layout01);
23-
sleep(2000);
24-
sort(layout01);
2523

2624
end;
2725

28-
procedure TSortInsertion.sort(layout01: TLayout);
26+
procedure TSortInsertion.sort();
2927
var
3028
i, j : Integer;
3129
key : Single;

modules/SelectionSort/U_Sort.Selection.pas

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ interface
55
uses U_SortClass, U_SortInterface, FMX.Layouts, System.SysUtils;
66

77
type
8-
TSortSelection = class(TSortClass, ISortInterface<TLayout>)
9-
private
10-
procedure sort(layout01 : TLayout);
11-
8+
TSortSelection = class(TSortClass, ISortInterface)
129
public
1310
constructor Create(layout01 : TLayout);
11+
12+
procedure sort(); Override;
13+
1414
end;
1515

1616
implementation
@@ -20,12 +20,10 @@ implementation
2020
constructor TSortSelection.Create(layout01: TLayout);
2121
begin
2222
inherited Create(layout01);
23-
sleep(2000);
24-
sort(layout01);
2523

2624
end;
2725

28-
procedure TSortSelection.sort(layout01: TLayout);
26+
procedure TSortSelection.sort();
2927
var
3028
i, j, min : Integer;
3129

project/Sorting.dproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@
298298
<DCC_DcuOutput>../output</DCC_DcuOutput>
299299
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
300300
<VerInfo_Locale>1046</VerInfo_Locale>
301-
<VerInfo_Build>21</VerInfo_Build>
301+
<VerInfo_Build>60</VerInfo_Build>
302302
<VerInfo_Debug>true</VerInfo_Debug>
303303
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion>
304-
<VerInfo_Keys>CompanyName=Bomrafinha;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.21;InternalName=SortingAlgorithms;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
304+
<VerInfo_Keys>CompanyName=Bomrafinha;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.60;InternalName=SortingAlgorithms;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
305305
<DCC_UnitSearchPath>../app;../output;$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
306306
</PropertyGroup>
307307
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''">

src/SortInterfaces/U_SortClass.pas

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,43 @@
22

33
interface
44
uses
5-
U_Sort.DTO.Retangle,
6-
FMX.Layouts, System.UITypes, System.SysUtils, FMX.Forms;
5+
U_Sort.DTO.Retangle, U_SortInterface,
6+
FMX.Layouts, System.UITypes, System.SysUtils, FMX.Forms, System.Classes;
77

88
type
9-
TSortClass = class(TInterfacedObject)
9+
TSortClass = class(TInterfacedObject, ISortInterface)
1010
private
1111
const
1212
fTempo : Integer = 500;
13+
fQtdRet : Integer = 50;
14+
1315
var
1416
fCor : Cardinal;
1517
fCorBorda : Cardinal;
1618
fCorMudanca : Cardinal;
1719
fLargura : Integer;
1820
fLarguraBorda : Integer;
1921
fRaio : Integer;
20-
fOwner : TLayout;
22+
2123
procedure criaRetangulo(posicao, posX, altura : integer);
2224
procedure preencheTela();
2325
procedure colorChange(ret01, ret02 : TRetangulo);
2426

2527
protected
28+
var
29+
fOwner : TLayout;
30+
2631
constructor Create(Owner : TLayout);
32+
33+
procedure algoritmo(); Virtual; Abstract;
2734
procedure troca(ret01, ret02 : TRetangulo);
2835
function findRectangle(posicao : Integer) : TRetangulo;
36+
2937
property Distancia : Integer read fLargura;
3038

39+
public
40+
procedure sort();
41+
3142
end;
3243

3344
implementation
@@ -54,9 +65,9 @@ constructor TSortClass.Create(Owner : TLayout);
5465
fCor := TAlphaColors.Hotpink;
5566
fCorBorda := TAlphaColors.Black;
5667
fCorMudanca := TAlphaColors.Skyblue;
57-
fLargura := 25;
5868
fLarguraBorda := 1;
59-
fRaio := 5;
69+
fLargura := trunc(Owner.Size.Width / fQtdRet);
70+
fRaio := trunc(fLargura * 0.20);
6071
preencheTela();
6172

6273
end;
@@ -95,20 +106,34 @@ procedure TSortClass.preencheTela;
95106
begin
96107
Randomize;
97108
posX := 0;
98-
for i := 0 to 49 do
109+
for i := 1 to fQtdRet do
99110
begin
100111
repeat
101112
tamanho := Random(490) + 10
102113
until ((tamanho mod 5) = 0);
103114

104-
criaRetangulo(i, posX, tamanho);
115+
criaRetangulo(i - 1, posX, tamanho);
105116
inc(posX, fLargura);
106-
107117
end;
118+
108119
Application.ProcessMessages;
109120

110121
end;
111122

123+
procedure TSortClass.sort;
124+
var
125+
alg : TThread;
126+
127+
begin
128+
alg := TThread.CreateAnonymousThread(
129+
procedure
130+
begin
131+
Self.algoritmo();
132+
end);
133+
alg.Start();
134+
135+
end;
136+
112137
procedure TSortClass.troca(ret01, ret02 : TRetangulo);
113138
var
114139
aux : Single;
@@ -124,6 +149,9 @@ procedure TSortClass.troca(ret01, ret02 : TRetangulo);
124149
ret02.Height := aux;
125150
ret01.Position.Y := fOwner.Height - ret01.Height;
126151
ret02.Position.Y := fOwner.Height - ret02.Height;
152+
ret01.Repaint;
153+
ret02.Repaint;
154+
fOwner.Repaint;
127155

128156
finally
129157
Sleep(fTempo);

src/SortInterfaces/U_SortInterface.pas

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
interface
44

55
type
6-
ISortInterface<T> = interface
6+
ISortInterface = interface
77
['{781A257F-C8E1-4616-AD89-2AD3FBF04260}']
88

9-
procedure sort(layout01 : T);
9+
procedure sort();
1010

1111
end;
1212

0 commit comments

Comments
 (0)