-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e39cb8
commit fb48d9b
Showing
35 changed files
with
146 additions
and
120 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace SortingAlgorithmVisualisation.Algorithms | ||
{ | ||
class CycleSort : AlgorithmBase | ||
{ | ||
public override int elementCount { get; set; } | ||
|
||
public override void BeginAlgorithm(int[] elements) | ||
{ | ||
elementCount = elements.Length; | ||
|
||
StartCycleSort(elements); | ||
|
||
DisplaySort.SortComplete = true; | ||
|
||
ShowCompletedDisplay(graphics, maxWidth, maxHeight, elements, threadDelay); | ||
} | ||
|
||
private void StartCycleSort(int[] elements) | ||
{ | ||
for(int i = 0; i < elementCount - 1; i++) | ||
{ | ||
int currentValue = elements[i]; | ||
int index = i + GetLargerThanCount(elements, currentValue, i); | ||
|
||
if(index == i) | ||
{ | ||
continue; | ||
} | ||
|
||
if(currentValue == elements[index]) | ||
{ | ||
index++; | ||
} | ||
|
||
int temp = elements[index]; | ||
elements[index] = currentValue; | ||
currentValue = temp; //Moves to next element | ||
ReDraw(elements, index); | ||
|
||
while (index != i) //Keeps looping until the next line is i + 0, meaning that the cycle is over | ||
{ | ||
index = i + GetLargerThanCount(elements, currentValue, i); | ||
|
||
while(currentValue == elements[index]) | ||
{ | ||
index++; | ||
} | ||
|
||
temp = elements[index]; | ||
elements[index] = currentValue; | ||
currentValue = temp; | ||
ReDraw(elements, index); | ||
} | ||
} | ||
} | ||
|
||
private int GetLargerThanCount(int[] elements, int currentValue, int lowerLimit) | ||
{ | ||
int count = 0; | ||
|
||
for (int j = lowerLimit + 1; j < elementCount; j++) | ||
{ | ||
if (elements[j] < currentValue) | ||
{ | ||
count++; | ||
} | ||
} | ||
|
||
return count; | ||
} | ||
|
||
private void ReDraw(int[] elements, int index) | ||
{ | ||
for (int i = 0; i < elementCount; i++) | ||
{ | ||
graphics.FillRectangle(new SolidBrush(SystemColors.ActiveBorder), i * maxWidth, 0, maxWidth, maxHeight); | ||
graphics.FillRectangle(new SolidBrush(Color.Black), i * maxWidth, maxHeight - elements[i], maxWidth, elements[i]); | ||
} | ||
|
||
graphics.FillRectangle(new SolidBrush(Color.DarkRed), index * maxWidth, maxHeight - elements[index], maxWidth, elements[index]); | ||
Thread.Sleep(threadDelay); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
SortingAlgorithmVisualisation/Forms/MainMenuForm.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
SortingAlgorithmVisualisation/bin/Debug/SortingAlgorithmVisualisation.application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1 KB
(100%)
SortingAlgorithmVisualisation/bin/Debug/SortingAlgorithmVisualisation.exe
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+4 KB
(100%)
SortingAlgorithmVisualisation/bin/Debug/SortingAlgorithmVisualisation.pdb
Binary file not shown.
Binary file modified
BIN
+1 KB
(100%)
SortingAlgorithmVisualisation/bin/Debug/app.publish/SortingAlgorithmVisualisation.exe
Binary file not shown.
6 changes: 3 additions & 3 deletions
6
SortingAlgorithmVisualisation/bin/Release/SortingAlgorithmVisualisation.application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+512 Bytes
(100%)
SortingAlgorithmVisualisation/bin/Release/SortingAlgorithmVisualisation.exe
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+4 KB
(100%)
SortingAlgorithmVisualisation/bin/Release/SortingAlgorithmVisualisation.pdb
Binary file not shown.
6 changes: 0 additions & 6 deletions
6
...les/SortingAlgorithmVisualisation_1_0_0_5/SortingAlgorithmVisualisation.exe.config.deploy
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-610 KB
...tion Files/SortingAlgorithmVisualisation_1_0_0_5/SortingAlgorithmVisualisation.exe.deploy
Binary file not shown.
Oops, something went wrong.