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 da8987f

Browse files
1.06 Release, Added Tree Sort
1 parent 3812e0f commit da8987f

File tree

41 files changed

+359
-74
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+359
-74
lines changed
32 KB
Binary file not shown.

‎README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<a href="https://scrutinizer-ci.com/g/pH7Software/pH7-Social-Dating-CMS/build-status/master">
99
<img src="https://scrutinizer-ci.com/g/pH7Software/pH7-Social-Dating-CMS/badges/build.png?b=master">
1010
</a>
11-
<a href="https://img.shields.io/badge/version-v1.05-blue">
12-
<img src="https://img.shields.io/badge/version-v1.05-blue">
11+
<a href="https://img.shields.io/badge/version-v1.06-blue">
12+
<img src="https://img.shields.io/badge/version-v1.06-blue">
1313
</a>
1414
<a href="https://github.com/nathanjukes/Sorting-Algorithm-Visualisation/blob/master/LICENSE.md">
1515
<img src="https://img.shields.io/github/license/Naereen/StrapDown.js.svg">
@@ -34,6 +34,8 @@ Or download here:
3434

3535
## Change Log
3636

37+
- 1.06 - Added Tree Sort (Pre-Order Traversal)
38+
3739
- 1.05 - Added Cycle Sort
3840

3941
- 1.04 - Added Odd-Even Sort
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Drawing;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace SortingAlgorithmVisualisation.Algorithms
12+
{
13+
class TreeSort : AlgorithmBase
14+
{
15+
public override int elementCount { get; set; }
16+
public Node root;
17+
public static int index = 0;
18+
19+
public override void BeginAlgorithm(int[] elements)
20+
{
21+
ReDrawClass.maxWidth = maxWidth;
22+
ReDrawClass.maxHeight = maxHeight;
23+
ReDrawClass.threadDelay = threadDelay;
24+
ReDrawClass.graphics = graphics;
25+
26+
CreateTree(elements);
27+
28+
ReDrawClass.ScanThroughAllElements(elements);
29+
30+
root.PreOrderTraversal(elements);
31+
32+
Thread.Sleep(220);
33+
}
34+
35+
private void CreateTree(int[] elements)
36+
{
37+
for(int i = 0; i < elementCount; i++)
38+
{
39+
if(root == null)
40+
{
41+
root = new Node(elements[i]);
42+
}
43+
else if(elements[i] < root.value)
44+
{
45+
root.AddNode(new Node(elements[i]));
46+
}
47+
else
48+
{
49+
root.AddNode(new Node(elements[i]));
50+
}
51+
}
52+
}
53+
}
54+
55+
class Node
56+
{
57+
public int value;
58+
private Node leftNode;
59+
private Node rightNode;
60+
private int count = 1;
61+
62+
public Node(int _value)
63+
{
64+
value = _value;
65+
}
66+
67+
public void AddNode(Node nodeToAdd)
68+
{
69+
if(nodeToAdd.value == value)
70+
{
71+
count++;
72+
}
73+
74+
if(nodeToAdd.value < value)
75+
{
76+
if(leftNode == null)
77+
{
78+
leftNode = nodeToAdd;
79+
}
80+
else
81+
{
82+
leftNode.AddNode(nodeToAdd);
83+
}
84+
}
85+
else if(nodeToAdd.value > value)
86+
{
87+
if (rightNode == null)
88+
{
89+
rightNode = nodeToAdd;
90+
}
91+
else
92+
{
93+
rightNode.AddNode(nodeToAdd);
94+
}
95+
}
96+
}
97+
98+
public void PreOrderTraversal(int[] elements)
99+
{
100+
if(leftNode != null)
101+
{
102+
leftNode.PreOrderTraversal(elements);
103+
}
104+
105+
for(int i = 0; i < count; i++)
106+
{
107+
elements[TreeSort.index] = value;
108+
TreeSort.index++;
109+
110+
ReDrawClass.ReDrawDisplay(elements, TreeSort.index);
111+
}
112+
113+
if(rightNode != null)
114+
{
115+
rightNode.PreOrderTraversal(elements);
116+
}
117+
}
118+
}
119+
120+
static class ReDrawClass
121+
{
122+
private static int elementCount;
123+
124+
public static int maxWidth;
125+
public static int maxHeight;
126+
public static int threadDelay;
127+
public static Graphics graphics;
128+
129+
public static void ReDrawDisplay(int[] elements, int currentIndex)
130+
{
131+
elementCount = elements.Length;
132+
133+
ClearDisplay(currentIndex - 1);
134+
135+
ReDrawElements(elements, currentIndex - 1);
136+
}
137+
138+
public static void ScanThroughAllElements(int[] elements) //Shows a demonstration of the Tree creation (Sifting through all elements and building a binary tree)
139+
{
140+
elementCount = elements.Length;
141+
142+
for (int i = 0; i < elementCount; i++)
143+
{
144+
graphics.FillRectangle(new SolidBrush(Color.DarkRed), i * maxWidth, maxHeight - elements[i], maxWidth, elements[i]);
145+
146+
Thread.Sleep(threadDelay);
147+
148+
graphics.FillRectangle(new SolidBrush(Color.Black), i * maxWidth, maxHeight - elements[i], maxWidth, elements[i]);
149+
}
150+
}
151+
152+
private static void ClearDisplay(int currentIndex)
153+
{
154+
graphics.FillRectangle(new SolidBrush(SystemColors.ActiveBorder), currentIndex * maxWidth, 0, maxWidth, maxHeight);
155+
}
156+
157+
private static void ReDrawElements(int[] elements, int currentIndex)
158+
{
159+
graphics.FillRectangle(new SolidBrush(Color.Black), currentIndex * maxWidth, maxHeight - elements[currentIndex], maxWidth, elements[currentIndex]);
160+
Thread.Sleep(threadDelay);
161+
}
162+
}
163+
164+
}

‎SortingAlgorithmVisualisation/Forms/DisplaySort.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ private void SetUpFormData(string _setModifier)
9393
{
9494
secondDelay.Text += threadDelay + 700 + "ms";
9595
}
96+
else if(algorithmName.Contains("Tree"))
97+
{
98+
secondDelay.Text += threadDelay + 220 + "ms";
99+
}
96100
else
97101
{
98102
secondDelay.Text += threadDelay + "ms";

‎SortingAlgorithmVisualisation/Forms/MainMenuForm.Designer.cs

Lines changed: 49 additions & 31 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ private bool SetAlgorithmData()
136136
algorithm = new CycleSort();
137137
algorithm.SetComplexity(4);
138138
break;
139+
case "Tree Sort":
140+
algorithm = new TreeSort();
141+
algorithm.SetComplexity(2);
142+
break;
139143
case null:
140144
MessageBox.Show("Please select an algorithm","Error");
141145
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>6</ApplicationRevision>
28+
<ApplicationRevision>7</ApplicationRevision>
2929
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
3030
<UseApplicationTrust>false</UseApplicationTrust>
3131
<PublishWizardCompleted>true</PublishWizardCompleted>
@@ -91,6 +91,7 @@
9191
<Compile Include="Algorithms\RadixSort.cs" />
9292
<Compile Include="Algorithms\SelectionSort.cs" />
9393
<Compile Include="Algorithms\ShellSort.cs" />
94+
<Compile Include="Algorithms\TreeSort.cs" />
9495
<Compile Include="Formatting\DataGeneration.cs" />
9596
<Compile Include="Forms\ComplexityPopUpForm.cs">
9697
<SubType>Form</SubType>
193 KB
Binary file not shown.

‎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.6" publicKeyToken="0000000000000000" language="en" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
3+
<assemblyIdentity name="SortingAlgorithmVisualisation.application" version="1.0.0.7" 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.6" publicKeyToken="0000000000000000" language="en" processorArchitecture="msil" type="win32" />
11+
<assemblyIdentity name="SortingAlgorithmVisualisation.exe" version="1.0.0.7" 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>qdr4fj6Yx63WqpRHAByXOsy+GCtuG1pRWpjtPxCGHnw=</dsig:DigestValue>
17+
<dsig:DigestValue>VOkcm0g8JuOVOEF9d+S37vU885aR/GcYsTW8ZYtqaTc=</dsig:DigestValue>
1818
</hash>
1919
</dependentAssembly>
2020
</dependency>
1.5 KB
Binary file not shown.

0 commit comments

Comments
(0)

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