@@ -22,16 +22,59 @@ public abstract class AlgorithmBase
22
22
public abstract int elementCount { get ; set ; }
23
23
public abstract void BeginAlgorithm ( int [ ] elements ) ;
24
24
25
- protected void ShowCompletedDisplay ( Graphics graphics , int maxWidth , int maxHeight , int [ ] elements , int threadDelay )
25
+ public void ShowCompletedDisplay ( int [ ] elements )
26
26
{
27
- FormattingDisplay formatDisplay = new FormattingDisplay ( ) ;
27
+ ShowAllGreen ( elements ) ;
28
+ }
29
+
30
+ private void ShowAllGreen ( int [ ] elements )
31
+ {
32
+ if ( threadDelay == 200 )
33
+ {
34
+ threadDelay = 80 ;
35
+ }
36
+ else if ( threadDelay == 0 )
37
+ {
38
+ threadDelay = 1 ;
39
+ }
40
+
41
+ for ( int i = 0 ; i < elements . Length ; i ++ )
42
+ {
43
+ graphics . FillRectangle ( new SolidBrush ( Color . FromArgb ( 83 , 153 , 182 ) ) , i * maxWidth , maxHeight - elements [ i ] , maxWidth , elements [ i ] ) ;
44
+ Thread . Sleep ( threadDelay ) ;
45
+ }
46
+ }
28
47
29
- formatDisplay . ShowAllGreen ( graphics , maxWidth , maxHeight , elements , threadDelay ) ;
48
+ public void SetComplexity ( int complexityRangeValue )
49
+ {
50
+ switch ( complexityRangeValue )
51
+ {
52
+ case 0 :
53
+ timeComplexity = "O(nLog(n))" ;
54
+ spaceComplexity = "O(1)" ;
55
+ break ;
56
+ case 1 :
57
+ timeComplexity = "O(nLog(n))" ;
58
+ spaceComplexity = "O(Log(n))" ;
59
+ break ;
60
+ case 2 :
61
+ timeComplexity = "O(nLog(n))" ;
62
+ spaceComplexity = "O(n)" ;
63
+ break ;
64
+ case 3 :
65
+ timeComplexity = "O(nk)" ;
66
+ spaceComplexity = "O(n+k)" ;
67
+ break ;
68
+ case 4 :
69
+ timeComplexity = "O(n²)" ;
70
+ spaceComplexity = "O(1)" ;
71
+ break ;
72
+ }
30
73
}
31
74
32
75
protected void SwapElements ( int index1 , int index2 , int [ ] elements , int sortType )
33
76
{
34
- switch ( sortType )
77
+ switch ( sortType )
35
78
{
36
79
case 0 :
37
80
graphics . FillRectangle ( new SolidBrush ( Color . DarkRed ) , index1 * maxWidth , maxHeight - elements [ index1 ] , maxWidth , elements [ index1 ] ) ;
@@ -58,7 +101,7 @@ protected void SwapElements(int index1, int index2, int[] elements, int sortType
58
101
elements [ index1 ] = elements [ index2 ] ;
59
102
elements [ index2 ] = tempValue ;
60
103
61
- switch ( sortType )
104
+ switch ( sortType )
62
105
{
63
106
default :
64
107
graphics . FillRectangle ( new SolidBrush ( Color . Black ) , index1 * maxWidth , maxHeight - elements [ index1 ] , maxWidth , elements [ index1 ] ) ;
@@ -68,11 +111,11 @@ protected void SwapElements(int index1, int index2, int[] elements, int sortType
68
111
graphics . FillRectangle ( new SolidBrush ( Color . DarkRed ) , index1 * maxWidth , maxHeight - elements [ index1 ] , maxWidth , elements [ index1 ] ) ;
69
112
graphics . FillRectangle ( new SolidBrush ( Color . Black ) , index2 * maxWidth , maxHeight - elements [ index2 ] , maxWidth , elements [ index2 ] ) ;
70
113
71
- if ( GetType ( ) . Name . Contains ( "Selection" ) )
114
+ if ( GetType ( ) . Name . Contains ( "Selection" ) )
72
115
{
73
116
Thread . Sleep ( threadDelay ) ;
74
117
}
75
-
118
+
76
119
graphics . FillRectangle ( new SolidBrush ( Color . Black ) , index1 * maxWidth , maxHeight - elements [ index1 ] , maxWidth , elements [ index1 ] ) ;
77
120
break ;
78
121
case 2 :
0 commit comments