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 3812e0f

Browse files
Cleaned up complexity attributes and removed redundant status' (Algorithm complete in each sort)
1 parent fb48d9b commit 3812e0f

File tree

53 files changed

+311
-197
lines changed

Some content is hidden

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

53 files changed

+311
-197
lines changed
-35 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.04-blue">
12-
<img src="https://img.shields.io/badge/version-v1.04-blue">
11+
<a href="https://img.shields.io/badge/version-v1.05-blue">
12+
<img src="https://img.shields.io/badge/version-v1.05-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.05 - Added Cycle Sort
38+
3739
- 1.04 - Added Odd-Even Sort
3840

3941
- 1.03 - Added Gnome Sort, Changed GUI Sizing

‎SortingAlgorithmVisualisation/Algorithms/AlgorithmBase.cs‎

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,59 @@ public abstract class AlgorithmBase
2222
public abstract int elementCount { get; set; }
2323
public abstract void BeginAlgorithm(int[] elements);
2424

25-
protected void ShowCompletedDisplay(Graphicsgraphics,intmaxWidth,intmaxHeight,int[] elements,intthreadDelay)
25+
public void ShowCompletedDisplay(int[] elements)
2626
{
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+
}
2847

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(n2)";
70+
spaceComplexity = "O(1)";
71+
break;
72+
}
3073
}
3174

3275
protected void SwapElements(int index1, int index2, int[] elements, int sortType)
3376
{
34-
switch(sortType)
77+
switch(sortType)
3578
{
3679
case 0:
3780
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
58101
elements[index1] = elements[index2];
59102
elements[index2] = tempValue;
60103

61-
switch(sortType)
104+
switch(sortType)
62105
{
63106
default:
64107
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
68111
graphics.FillRectangle(new SolidBrush(Color.DarkRed), index1 * maxWidth, maxHeight - elements[index1], maxWidth, elements[index1]);
69112
graphics.FillRectangle(new SolidBrush(Color.Black), index2 * maxWidth, maxHeight - elements[index2], maxWidth, elements[index2]);
70113

71-
if(GetType().Name.Contains("Selection"))
114+
if(GetType().Name.Contains("Selection"))
72115
{
73116
Thread.Sleep(threadDelay);
74117
}
75-
118+
76119
graphics.FillRectangle(new SolidBrush(Color.Black), index1 * maxWidth, maxHeight - elements[index1], maxWidth, elements[index1]);
77120
break;
78121
case 2:

‎SortingAlgorithmVisualisation/Algorithms/BogoSort.cs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class BogoSort : AlgorithmBase
1515
private int[] elementsCopy;
1616
public override void BeginAlgorithm(int[] elements)
1717
{
18-
elementCount = elements.Length;
19-
2018
elementsCopy = (int[])elements.Clone();
2119

2220
StartBogoSort(elements);
@@ -54,7 +52,7 @@ private void StartBogoSort(int[] elements)
5452
if (CheckIfSorted(elements))
5553
{
5654
DisplaySort.SortComplete = true;
57-
ShowCompletedDisplay(graphics,maxWidth,maxHeight,elements,threadDelay);
55+
ShowCompletedDisplay(elements);
5856
break;
5957
}
6058
else

‎SortingAlgorithmVisualisation/Algorithms/BubbleSort.cs‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ class BubbleSort : AlgorithmBase
1515

1616
public override void BeginAlgorithm(int[] elements)
1717
{
18-
elementCount = elements.Length;
19-
20-
Sort(elements, graphics, maxWidth, maxHeight);
21-
22-
DisplaySort.SortComplete = true;
18+
StartBubbleSort(elements);
2319
}
2420

25-
private void Sort(int[] elements,Graphicsgraphics,intmaxWidth,intmaxHeight)
21+
private void StartBubbleSort(int[] elements)
2622
{
2723
for (int i = 0; i < elementCount; i++)
2824
{
@@ -34,8 +30,6 @@ private void Sort(int[] elements, Graphics graphics, int maxWidth, int maxHeight
3430
}
3531
}
3632
}
37-
38-
ShowCompletedDisplay(graphics, maxWidth, maxHeight, elements, threadDelay);
3933
}
4034
}
4135
}

‎SortingAlgorithmVisualisation/Algorithms/CocktailSort.cs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ class CocktailSort : AlgorithmBase
1515

1616
public override void BeginAlgorithm(int[] elements)
1717
{
18-
elementCount = elements.Length;
19-
2018
StartCocktailSort(elements);
21-
22-
DisplaySort.SortComplete = true;
23-
24-
ShowCompletedDisplay(graphics, maxWidth, maxHeight, elements, threadDelay);
2519
}
2620

2721
private void StartCocktailSort(int[] elements)

‎SortingAlgorithmVisualisation/Algorithms/CombSort.cs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,7 @@ class CombSort : AlgorithmBase
1313

1414
public override void BeginAlgorithm(int[] elements)
1515
{
16-
elementCount = elements.Length;
17-
1816
StartCombSort(elements);
19-
20-
DisplaySort.SortComplete = true;
21-
22-
ShowCompletedDisplay(graphics, maxWidth, maxHeight, elements, threadDelay);
2317
}
2418

2519
private void StartCombSort(int[] elements)

‎SortingAlgorithmVisualisation/Algorithms/CycleSort.cs‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Drawing;
44
using System.Linq;
@@ -15,13 +15,7 @@ class CycleSort : AlgorithmBase
1515

1616
public override void BeginAlgorithm(int[] elements)
1717
{
18-
elementCount = elements.Length;
19-
2018
StartCycleSort(elements);
21-
22-
DisplaySort.SortComplete = true;
23-
24-
ShowCompletedDisplay(graphics, maxWidth, maxHeight, elements, threadDelay);
2519
}
2620

2721
private void StartCycleSort(int[] elements)

‎SortingAlgorithmVisualisation/Algorithms/GnomeSort.cs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,13 @@ class GnomeSort : AlgorithmBase
1313

1414
public override void BeginAlgorithm(int[] elements)
1515
{
16-
elementCount = elements.Length;
17-
1816
StartGnomeSort(elements);
19-
20-
DisplaySort.SortComplete = true;
21-
22-
ShowCompletedDisplay(graphics, maxWidth, maxHeight, elements, threadDelay);
2317
}
2418

2519
private void StartGnomeSort(int[] elements)
2620
{
2721
for(int i = 0; i < elementCount; i++)
2822
{
29-
3023
if(i + 1 < elementCount && i >= 0 && elements[i] > elements[i + 1])
3124
{
3225
SwapElements(i, i + 1, elements, 1);

‎SortingAlgorithmVisualisation/Algorithms/HeapSort.cs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class HeapSort : AlgorithmBase
2020

2121
public override void BeginAlgorithm(int[] elements)
2222
{
23-
elementCount = elements.Length;
24-
2523
sortedLength = elementCount;
2624

2725
if (elementCount % 2 == 0)
@@ -33,10 +31,6 @@ public override void BeginAlgorithm(int[] elements)
3331
Heapify(elements);
3432

3533
DeleteElements(elements);
36-
37-
DisplaySort.SortComplete = true;
38-
39-
ShowCompletedDisplay(graphics, maxWidth, maxHeight, elements, threadDelay);
4034
}
4135

4236
private void Heapify(int[] elements)

0 commit comments

Comments
(0)

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