Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb48d9b

Browse files
Added Cycle Sort
1 parent 8e39cb8 commit fb48d9b

File tree

35 files changed

+146
-120
lines changed

35 files changed

+146
-120
lines changed
-1 KB
Binary file not shown.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using System.Windows.Forms;
9+
10+
namespace SortingAlgorithmVisualisation.Algorithms
11+
{
12+
class CycleSort : AlgorithmBase
13+
{
14+
public override int elementCount { get; set; }
15+
16+
public override void BeginAlgorithm(int[] elements)
17+
{
18+
elementCount = elements.Length;
19+
20+
StartCycleSort(elements);
21+
22+
DisplaySort.SortComplete = true;
23+
24+
ShowCompletedDisplay(graphics, maxWidth, maxHeight, elements, threadDelay);
25+
}
26+
27+
private void StartCycleSort(int[] elements)
28+
{
29+
for(int i = 0; i < elementCount - 1; i++)
30+
{
31+
int currentValue = elements[i];
32+
int index = i + GetLargerThanCount(elements, currentValue, i);
33+
34+
if(index == i)
35+
{
36+
continue;
37+
}
38+
39+
if(currentValue == elements[index])
40+
{
41+
index++;
42+
}
43+
44+
int temp = elements[index];
45+
elements[index] = currentValue;
46+
currentValue = temp; //Moves to next element
47+
ReDraw(elements, index);
48+
49+
while (index != i) //Keeps looping until the next line is i + 0, meaning that the cycle is over
50+
{
51+
index = i + GetLargerThanCount(elements, currentValue, i);
52+
53+
while(currentValue == elements[index])
54+
{
55+
index++;
56+
}
57+
58+
temp = elements[index];
59+
elements[index] = currentValue;
60+
currentValue = temp;
61+
ReDraw(elements, index);
62+
}
63+
}
64+
}
65+
66+
private int GetLargerThanCount(int[] elements, int currentValue, int lowerLimit)
67+
{
68+
int count = 0;
69+
70+
for (int j = lowerLimit + 1; j < elementCount; j++)
71+
{
72+
if (elements[j] < currentValue)
73+
{
74+
count++;
75+
}
76+
}
77+
78+
return count;
79+
}
80+
81+
private void ReDraw(int[] elements, int index)
82+
{
83+
for (int i = 0; i < elementCount; i++)
84+
{
85+
graphics.FillRectangle(new SolidBrush(SystemColors.ActiveBorder), i * maxWidth, 0, maxWidth, maxHeight);
86+
graphics.FillRectangle(new SolidBrush(Color.Black), i * maxWidth, maxHeight - elements[i], maxWidth, elements[i]);
87+
}
88+
89+
graphics.FillRectangle(new SolidBrush(Color.DarkRed), index * maxWidth, maxHeight - elements[index], maxWidth, elements[index]);
90+
Thread.Sleep(threadDelay);
91+
}
92+
}
93+
}

‎SortingAlgorithmVisualisation/Algorithms/OddEvenSort.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Threading.Tasks;
6+
using System.Windows.Forms;
67

78
namespace SortingAlgorithmVisualisation.Algorithms
89
{

‎SortingAlgorithmVisualisation/Forms/MainMenuForm.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎SortingAlgorithmVisualisation/Forms/MainMenuForm.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ private bool SetAlgorithmData()
143143
algorithm = new OddEvenSort();
144144
algorithm.timeComplexity = ("O(n2)");
145145
algorithm.spaceComplexity = ("O(1)");
146-
break;
146+
break;
147+
case "Cycle Sort":
148+
algorithm = new CycleSort();
149+
algorithm.timeComplexity = ("O(n2)");
150+
algorithm.spaceComplexity = ("O(1)");
151+
break;
147152
case null:
148153
MessageBox.Show("Please select an algorithm","Error");
149154
return false;

‎SortingAlgorithmVisualisation/SortingAlgorithmVisualisation.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<TargetCulture>en</TargetCulture>
2626
<ProductName>Sorting Algorithm Visualiser</ProductName>
2727
<PublisherName>Nathan Jukes</PublisherName>
28-
<ApplicationRevision>5</ApplicationRevision>
28+
<ApplicationRevision>6</ApplicationRevision>
2929
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
3030
<UseApplicationTrust>false</UseApplicationTrust>
3131
<PublishWizardCompleted>true</PublishWizardCompleted>
@@ -81,6 +81,7 @@
8181
<Compile Include="Algorithms\BubbleSort.cs" />
8282
<Compile Include="Algorithms\CocktailSort.cs" />
8383
<Compile Include="Algorithms\CombSort.cs" />
84+
<Compile Include="Algorithms\CycleSort.cs" />
8485
<Compile Include="Algorithms\GnomeSort.cs" />
8586
<Compile Include="Algorithms\HeapSort.cs" />
8687
<Compile Include="Algorithms\InsertionSort.cs" />

‎SortingAlgorithmVisualisation/bin/Debug/SortingAlgorithmVisualisation.application

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
3-
<assemblyIdentity name="SortingAlgorithmVisualisation.application" version="1.0.0.5" publicKeyToken="0000000000000000" language="en" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
3+
<assemblyIdentity name="SortingAlgorithmVisualisation.application" version="1.0.0.6" publicKeyToken="0000000000000000" language="en" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
44
<description asmv2:publisher="Nathan Jukes" asmv2:product="Sorting Algorithm Visualiser" xmlns="urn:schemas-microsoft-com:asm.v1" />
55
<deployment install="true" mapFileExtensions="true" />
66
<compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
77
<framework targetVersion="4.6.1" profile="Full" supportedRuntime="4.0.30319" />
88
</compatibleFrameworks>
99
<dependency>
1010
<dependentAssembly dependencyType="install" codebase="SortingAlgorithmVisualisation.exe.manifest" size="3578">
11-
<assemblyIdentity name="SortingAlgorithmVisualisation.exe" version="1.0.0.5" publicKeyToken="0000000000000000" language="en" processorArchitecture="msil" type="win32" />
11+
<assemblyIdentity name="SortingAlgorithmVisualisation.exe" version="1.0.0.6" publicKeyToken="0000000000000000" language="en" processorArchitecture="msil" type="win32" />
1212
<hash>
1313
<dsig:Transforms>
1414
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
1515
</dsig:Transforms>
1616
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
17-
<dsig:DigestValue>qGsPZ30xKFPlDgjcVVyWGSKf2aHGrzpf5IY1JLKUbyI=</dsig:DigestValue>
17+
<dsig:DigestValue>s+ZIU2P6mlGzoRNVe7imAEOMP6B/NNK8I5jPamee5JQ=</dsig:DigestValue>
1818
</hash>
1919
</dependentAssembly>
2020
</dependency>
1 KB
Binary file not shown.

‎SortingAlgorithmVisualisation/bin/Debug/SortingAlgorithmVisualisation.exe.manifest

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
3-
<asmv1:assemblyIdentity name="SortingAlgorithmVisualisation.exe" version="1.0.0.5" publicKeyToken="0000000000000000" language="en" processorArchitecture="msil" type="win32" />
3+
<asmv1:assemblyIdentity name="SortingAlgorithmVisualisation.exe" version="1.0.0.6" publicKeyToken="0000000000000000" language="en" processorArchitecture="msil" type="win32" />
44
<application />
55
<entryPoint>
66
<assemblyIdentity name="SortingAlgorithmVisualisation" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
@@ -42,14 +42,14 @@
4242
</dependentAssembly>
4343
</dependency>
4444
<dependency>
45-
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="SortingAlgorithmVisualisation.exe" size="626696">
45+
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="SortingAlgorithmVisualisation.exe" size="627720">
4646
<assemblyIdentity name="SortingAlgorithmVisualisation" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
4747
<hash>
4848
<dsig:Transforms>
4949
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
5050
</dsig:Transforms>
5151
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
52-
<dsig:DigestValue>JqWDp9YGUyQCnckAgzvcpzoePQJ8tYByCR0irr/uffk=</dsig:DigestValue>
52+
<dsig:DigestValue>5Ns1YxxulkL82DbuMQvuz4/8ezrRdVSAiuSU0Ixq/gM=</dsig:DigestValue>
5353
</hash>
5454
</dependentAssembly>
5555
</dependency>
4 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /