├── .gitattributes ├── .gitignore ├── README.md ├── SortVisualizer.sln ├── SortVisualizer ├── Algorithms │ ├── BubbleSort.cs │ ├── InsertionSort.cs │ ├── MergeSort.cs │ ├── QuickSort.cs │ └── SelectionSort.cs ├── App.config ├── Form │ ├── Form1.Designer.cs │ ├── Form1.cs │ └── Form1.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── SortInterface.cs └── SortVisualizer.csproj └── resources ├── BubbleSort.gif ├── InsertionSort.gif ├── MergeSort.gif └── SelectionSort.gif /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sorting Visualizer 2 | A Sorting Visualizer implemented using C# and Windows Forms Application. 3 | 4 | The application visualizes an array of unsorted integers as bars. Each bar has a height corresponding to the value at that position in the array. From here, the array is sorted and the bars indicate movement of the integers within the array throughout the sorting algorithm. 5 |

6 | The following algorithms have been implemented into the application: 7 | 8 | * Insertion Sort 9 | * Selection Sort 10 | * Bubble Sort 11 | * Merge Sort 12 | 13 | 14 | More algorithms to be added in the future! 15 |
16 | ### Merge Sort 17 | 18 | ![Merge Sort Visualization](./resources/MergeSort.gif) 19 | 20 | 21 | ### Insertion Sort 22 | 23 | ![Insertion Sort Visualization](./resources/InsertionSort.gif) 24 | 25 | 26 | 27 | ### Selection Sort 28 | 29 | 30 | ![Selection Sort Visualization](./resources/SelectionSort.gif) 31 | 32 | 33 | 34 | 35 | ### Bubble Sort 36 | 37 | 38 | ![Bubble Sort Visualization](./resources/BubbleSort.gif) 39 | -------------------------------------------------------------------------------- /SortVisualizer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30105.148 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SortVisualizer", "SortVisualizer\SortVisualizer.csproj", "{177A9B98-DDF9-40D3-AAC3-96ED95CDB476}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {177A9B98-DDF9-40D3-AAC3-96ED95CDB476}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {177A9B98-DDF9-40D3-AAC3-96ED95CDB476}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {177A9B98-DDF9-40D3-AAC3-96ED95CDB476}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {177A9B98-DDF9-40D3-AAC3-96ED95CDB476}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {F51D676E-0E6A-4B7A-8E68-BECB53B36247} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SortVisualizer/Algorithms/BubbleSort.cs: -------------------------------------------------------------------------------- 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 | 8 | 9 | namespace SortVisualizer 10 | { 11 | class BubbleSort : SortInterface 12 | { 13 | 14 | private int[] mainArray; 15 | private Graphics g; 16 | private int MaxVal; // Max Val of bar Height 17 | Brush RedBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); 18 | Brush BlackBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); 19 | 20 | public BubbleSort(int[] mainArray, Graphics g, int MaxVal) 21 | { 22 | this.mainArray = mainArray; 23 | this.g = g; 24 | this.MaxVal = MaxVal; 25 | } 26 | 27 | 28 | public void nextStep() 29 | { 30 | for (int i = 0; i < mainArray.Count() - 1; i++) 31 | { 32 | if (mainArray[i] > mainArray[i + 1]) 33 | { 34 | swap(i, i + 1); 35 | } 36 | } 37 | } 38 | 39 | 40 | private void swap(int i, int v) 41 | { 42 | int temp = mainArray[i]; 43 | mainArray[i] = mainArray[i + 1]; 44 | mainArray[i + 1] = temp; 45 | 46 | drawBar(i, mainArray[i]); 47 | drawBar(v, mainArray[v]); 48 | } 49 | 50 | private void drawBar(int position, int height) 51 | { 52 | g.FillRectangle(BlackBrush, position, 0, 1, MaxVal); 53 | g.FillRectangle(RedBrush, position, MaxVal - mainArray[position], 1, MaxVal); 54 | } 55 | 56 | public bool isSorted() 57 | { 58 | for (int i = 0; i < mainArray.Count() - 1; i++) 59 | { 60 | if(mainArray[i] > mainArray[i + 1]) 61 | { 62 | return false; 63 | } 64 | } 65 | return true; 66 | } 67 | 68 | public void reDraw() 69 | { 70 | for(int i = 0; i < (mainArray.Count() - 1); i++) 71 | { 72 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), i, MaxVal - mainArray[i], 1, MaxVal); 73 | } 74 | } 75 | 76 | public void completeSort() 77 | { 78 | for (int i = 0; i < (mainArray.Count() - 1); i++) 79 | { 80 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Yellow), i, MaxVal - mainArray[i], 1, MaxVal); 81 | System.Threading.Thread.Sleep(1); 82 | } 83 | 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /SortVisualizer/Algorithms/InsertionSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SortVisualizer 9 | { 10 | class InsertionSort : SortInterface 11 | { 12 | private int[] mainArray; 13 | private Graphics g; 14 | private int MaxVal; // Max Val of bar Height 15 | Brush RedBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); 16 | Brush BlackBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); 17 | public InsertionSort(int[] mainArray, Graphics g, int MaxVal) 18 | { 19 | this.mainArray = mainArray; 20 | this.g = g; 21 | this.MaxVal = MaxVal; 22 | } 23 | public bool isSorted() 24 | { 25 | for (int i = 0; i < mainArray.Count() - 1; i++) 26 | { 27 | if (mainArray[i] > mainArray[i + 1]) 28 | { 29 | return false; 30 | } 31 | } 32 | return true; 33 | } 34 | 35 | private void drawBar(int position, int height) 36 | { 37 | 38 | g.FillRectangle(BlackBrush, position, 0, 1, MaxVal); 39 | g.FillRectangle(RedBrush, position, MaxVal - mainArray[position], 1, MaxVal); 40 | } 41 | 42 | public void nextStep() 43 | { 44 | for (int i = 1; i < mainArray.Count(); i++) 45 | { 46 | slide(mainArray, i); 47 | } 48 | } 49 | 50 | private void slide(int[] mainArray, int loc) 51 | { 52 | int temp = mainArray[loc]; 53 | int j = loc; 54 | while(j > 0 && mainArray[j-1] > temp) 55 | { 56 | mainArray[j] = mainArray[j - 1]; 57 | drawBar(j, mainArray[j-1]); 58 | j--; 59 | } 60 | mainArray[j] = temp; 61 | drawBar(j, temp); 62 | 63 | } 64 | 65 | public void reDraw() 66 | { 67 | for (int i = 0; i < (mainArray.Count() - 1); i++) 68 | { 69 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), i, MaxVal - mainArray[i], 1, MaxVal); 70 | } 71 | } 72 | public void completeSort() 73 | { 74 | for (int i = 0; i < (mainArray.Count() - 1); i++) 75 | { 76 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Blue), i, MaxVal - mainArray[i], 1, MaxVal); 77 | System.Threading.Thread.Sleep(1); 78 | } 79 | 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /SortVisualizer/Algorithms/MergeSort.cs: -------------------------------------------------------------------------------- 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 | 9 | namespace SortVisualizer 10 | { 11 | class MergeSort : SortInterface 12 | { 13 | private int[] mainArray; 14 | private Graphics g; 15 | private int MaxVal; // Max Val of bar Height 16 | Brush RedBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); 17 | Brush BlackBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); 18 | 19 | 20 | public MergeSort(int[] mainArray, Graphics g, int MaxVal) 21 | { 22 | this.mainArray = mainArray; 23 | this.g = g; 24 | this.MaxVal = MaxVal; 25 | } 26 | public bool isSorted() 27 | { 28 | for (int i = 0; i < mainArray.Count() - 1; i++) 29 | { 30 | if (mainArray[i] > mainArray[i + 1]) 31 | { 32 | return false; 33 | } 34 | } 35 | return true; 36 | } 37 | 38 | private void drawBar(int position, int height) 39 | { 40 | 41 | g.FillRectangle(BlackBrush, position, 0, 1, MaxVal); 42 | g.FillRectangle(RedBrush, position, MaxVal - mainArray[position], 1, MaxVal); 43 | } 44 | 45 | public void nextStep() 46 | { 47 | mergeSort(mainArray, 0, mainArray.Count() - 1); 48 | } 49 | 50 | private void mergeSort(int[] mainArray, int lo, int hi) 51 | { 52 | if (lo < hi) 53 | { 54 | int middle = (lo + hi) / 2; 55 | 56 | 57 | mergeSort(mainArray, lo, middle); 58 | mergeSort(mainArray, middle + 1, hi); 59 | 60 | Merge(mainArray, lo, middle, hi); 61 | } 62 | } 63 | 64 | 65 | 66 | private void Merge(int[] mainArray, int lo, int middle, int hi) 67 | { 68 | int[] leftArray = new int[middle - lo + 1]; 69 | int[] rightArray = new int[hi - middle]; 70 | 71 | Array.Copy(mainArray, lo, leftArray, 0, middle - lo + 1); 72 | Array.Copy(mainArray, middle + 1, rightArray, 0, hi - middle); 73 | 74 | int i = 0; 75 | int j = 0; 76 | for (int k = lo; k < hi + 1; k++) 77 | { 78 | if (i == leftArray.Length) 79 | { 80 | mainArray[k] = rightArray[j]; 81 | drawBar(k, mainArray[k]); 82 | System.Threading.Thread.Sleep(1); 83 | j++; 84 | } 85 | else if (j == rightArray.Length) 86 | { 87 | mainArray[k] = leftArray[i]; 88 | drawBar(k, mainArray[k]); 89 | System.Threading.Thread.Sleep(1); 90 | i++; 91 | } 92 | else if (leftArray[i] <= rightArray[j]) 93 | { 94 | mainArray[k] = leftArray[i]; 95 | drawBar(k, mainArray[k]); 96 | System.Threading.Thread.Sleep(1); 97 | i++; 98 | } 99 | else 100 | { 101 | mainArray[k] = rightArray[j]; 102 | drawBar(k, mainArray[k]); 103 | System.Threading.Thread.Sleep(1); 104 | j++; 105 | } 106 | } 107 | } 108 | 109 | /*private void slide(int[] mainArray, int loc) 110 | { 111 | int temp = mainArray[loc]; 112 | int j = loc; 113 | while (j > 0 && mainArray[j - 1] > temp) 114 | { 115 | mainArray[j] = mainArray[j - 1]; 116 | drawBar(j, mainArray[j - 1]); 117 | j--; 118 | } 119 | mainArray[j] = temp; 120 | drawBar(j, temp); 121 | 122 | }*/ 123 | 124 | public void reDraw() 125 | { 126 | for (int i = 0; i < (mainArray.Count() - 1); i++) 127 | { 128 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), i, MaxVal - mainArray[i], 1, MaxVal); 129 | } 130 | } 131 | public void completeSort() 132 | { 133 | for (int i = 0; i < (mainArray.Count() - 1); i++) 134 | { 135 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Purple), i, MaxVal - mainArray[i], 1, MaxVal); 136 | System.Threading.Thread.Sleep(1); 137 | } 138 | 139 | } 140 | 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /SortVisualizer/Algorithms/QuickSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SortVisualizer 9 | { 10 | class QuickSort : SortInterface 11 | { 12 | private int[] mainArray; 13 | private Graphics g; 14 | private int MaxVal; // Max Val of bar Height 15 | Brush RedBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); 16 | Brush BlackBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); 17 | public QuickSort(int[] mainArray, Graphics g, int MaxVal) 18 | { 19 | this.mainArray = mainArray; 20 | this.g = g; 21 | this.MaxVal = MaxVal; 22 | } 23 | public bool isSorted() 24 | { 25 | for (int i = 0; i < mainArray.Count() - 1; i++) 26 | { 27 | if (mainArray[i] > mainArray[i + 1]) 28 | { 29 | return false; 30 | } 31 | } 32 | return true; 33 | } 34 | 35 | private void drawBar(int position, int height) 36 | { 37 | 38 | g.FillRectangle(BlackBrush, position, 0, 1, MaxVal); 39 | g.FillRectangle(RedBrush, position, MaxVal - mainArray[position], 1, MaxVal); 40 | } 41 | 42 | public void nextStep() 43 | { 44 | for (int i = 1; i < mainArray.Count(); i++) 45 | { 46 | quickSort(mainArray, 0, mainArray.Count() - 1); 47 | } 48 | } 49 | 50 | private void quickSort(int[] mainArray, int left, int right) 51 | { 52 | int i; 53 | if (left < right) 54 | { 55 | i = partition(mainArray, left, right); 56 | 57 | quickSort(mainArray, left, i - 1); 58 | quickSort(mainArray, i + 1, right); 59 | } 60 | } 61 | 62 | private int partition(int[] mainArray, int left, int right) 63 | { 64 | int pivot = mainArray[right]; 65 | 66 | // index of smaller element 67 | int i = (left - 1); 68 | for (int j = left; j < right; j++) 69 | { 70 | // If current element is smaller 71 | // than the pivot 72 | if (mainArray[j] < pivot) 73 | { 74 | i++; 75 | 76 | // swap arr[i] and arr[j] 77 | int temp = mainArray[i]; 78 | mainArray[i] = mainArray[j]; 79 | drawBar(i, mainArray[i]); 80 | mainArray[j] = temp; 81 | drawBar(j, mainArray[j]); 82 | } 83 | } 84 | 85 | // swap arr[i+1] and arr[high] (or pivot) 86 | int temp1 = mainArray[i + 1]; 87 | mainArray[i + 1] = mainArray[right]; 88 | drawBar(i+1, mainArray[i+1]); 89 | mainArray[right] = temp1; 90 | drawBar(right, mainArray[right]); 91 | 92 | return i + 1; 93 | } 94 | 95 | private void slide(int[] mainArray, int loc) 96 | { 97 | int temp = mainArray[loc]; 98 | int j = loc; 99 | while (j > 0 && mainArray[j - 1] > temp) 100 | { 101 | mainArray[j] = mainArray[j - 1]; 102 | drawBar(j, mainArray[j - 1]); 103 | j--; 104 | } 105 | mainArray[j] = temp; 106 | drawBar(j, temp); 107 | 108 | } 109 | 110 | public void reDraw() 111 | { 112 | for (int i = 0; i < (mainArray.Count() - 1); i++) 113 | { 114 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), i, MaxVal - mainArray[i], 1, MaxVal); 115 | } 116 | } 117 | public void completeSort() 118 | { 119 | for (int i = 0; i < (mainArray.Count() - 1); i++) 120 | { 121 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.White), i, MaxVal - mainArray[i], 1, MaxVal); 122 | System.Threading.Thread.Sleep(1); 123 | } 124 | 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /SortVisualizer/Algorithms/SelectionSort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SortVisualizer 9 | { 10 | class SelectionSort : SortInterface 11 | { 12 | private int[] mainArray; 13 | private Graphics g; 14 | private int MaxVal; // Max Val of bar Height 15 | Brush RedBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); 16 | Brush BlueBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); 17 | Brush BlackBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); 18 | 19 | public SelectionSort(int[] mainArray, Graphics g, int MaxVal) 20 | { 21 | this.mainArray = mainArray; 22 | this.g = g; 23 | this.MaxVal = MaxVal; 24 | } 25 | 26 | public bool isSorted() 27 | { 28 | 29 | for (int i = 0; i < mainArray.Count() - 1; i++) 30 | { 31 | if (mainArray[i] > mainArray[i + 1]) 32 | { 33 | return false; 34 | } 35 | } 36 | return true; 37 | } 38 | 39 | public void nextStep() 40 | { 41 | for (int i = 0; i < mainArray.Count(); i++) 42 | { 43 | int min = FindMin(mainArray, i); 44 | int temp = mainArray[i]; 45 | mainArray[i] = mainArray[min]; 46 | drawBar(i, mainArray[min]); 47 | System.Threading.Thread.Sleep(5); 48 | mainArray[min] = temp; 49 | drawBar(min, temp); 50 | System.Threading.Thread.Sleep(5); 51 | } 52 | } 53 | 54 | private void drawBar(int position, int height) 55 | { 56 | 57 | g.FillRectangle(BlackBrush, position, 0, 1, MaxVal); 58 | g.FillRectangle(BlueBrush, position, MaxVal - mainArray[position], 1, MaxVal); 59 | g.FillRectangle(RedBrush, position, MaxVal - mainArray[position], 1, MaxVal); 60 | } 61 | 62 | private int FindMin(int[] mainArray, int a) 63 | { 64 | int retloc = a; 65 | int voi = mainArray[a]; 66 | for (int i = a + 1; i < mainArray.Count(); i++) 67 | { 68 | if (mainArray[i] < voi) 69 | { 70 | retloc = i; 71 | voi = mainArray[i]; 72 | } 73 | 74 | } 75 | return retloc; 76 | } 77 | 78 | public void reDraw() 79 | { 80 | for (int i = 0; i < (mainArray.Count() - 1); i++) 81 | { 82 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), i, MaxVal - mainArray[i], 1, MaxVal); 83 | } 84 | } 85 | public void completeSort() 86 | { 87 | for (int i = 0; i < (mainArray.Count() - 1); i++) 88 | { 89 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Green), i, MaxVal - mainArray[i], 1, MaxVal); 90 | System.Threading.Thread.Sleep(1); 91 | } 92 | 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /SortVisualizer/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /SortVisualizer/Form/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SortVisualizer 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.menuStrip1 = new System.Windows.Forms.MenuStrip(); 32 | this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 33 | this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 34 | this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 35 | this.contactMeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 36 | this.linkedinToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 37 | this.label1 = new System.Windows.Forms.Label(); 38 | this.comboBox1 = new System.Windows.Forms.ComboBox(); 39 | this.btnReset = new System.Windows.Forms.Button(); 40 | this.panel1 = new System.Windows.Forms.Panel(); 41 | this.button1 = new System.Windows.Forms.Button(); 42 | this.btnPause = new System.Windows.Forms.Button(); 43 | this.menuStrip1.SuspendLayout(); 44 | this.SuspendLayout(); 45 | // 46 | // menuStrip1 47 | // 48 | this.menuStrip1.BackColor = System.Drawing.Color.Lavender; 49 | this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); 50 | this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 51 | this.fileToolStripMenuItem, 52 | this.helpToolStripMenuItem}); 53 | this.menuStrip1.Location = new System.Drawing.Point(0, 0); 54 | this.menuStrip1.Name = "menuStrip1"; 55 | this.menuStrip1.Size = new System.Drawing.Size(1331, 28); 56 | this.menuStrip1.TabIndex = 0; 57 | this.menuStrip1.Text = "menuStrip1"; 58 | this.menuStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.menuStrip1_ItemClicked); 59 | // 60 | // fileToolStripMenuItem 61 | // 62 | this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 63 | this.exitToolStripMenuItem}); 64 | this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; 65 | this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24); 66 | this.fileToolStripMenuItem.Text = "File"; 67 | this.fileToolStripMenuItem.Click += new System.EventHandler(this.fileToolStripMenuItem_Click); 68 | // 69 | // exitToolStripMenuItem 70 | // 71 | this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; 72 | this.exitToolStripMenuItem.Size = new System.Drawing.Size(116, 26); 73 | this.exitToolStripMenuItem.Text = "Exit"; 74 | this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); 75 | // 76 | // helpToolStripMenuItem 77 | // 78 | this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 79 | this.contactMeToolStripMenuItem}); 80 | this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; 81 | this.helpToolStripMenuItem.Size = new System.Drawing.Size(55, 24); 82 | this.helpToolStripMenuItem.Text = "Help"; 83 | // 84 | // contactMeToolStripMenuItem 85 | // 86 | this.contactMeToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 87 | this.linkedinToolStripMenuItem}); 88 | this.contactMeToolStripMenuItem.Name = "contactMeToolStripMenuItem"; 89 | this.contactMeToolStripMenuItem.Size = new System.Drawing.Size(224, 26); 90 | this.contactMeToolStripMenuItem.Text = "Contact Me"; 91 | // 92 | // linkedinToolStripMenuItem 93 | // 94 | this.linkedinToolStripMenuItem.Name = "linkedinToolStripMenuItem"; 95 | this.linkedinToolStripMenuItem.Size = new System.Drawing.Size(224, 26); 96 | this.linkedinToolStripMenuItem.Text = "Github"; 97 | // 98 | // label1 99 | // 100 | this.label1.AutoSize = true; 101 | this.label1.BackColor = System.Drawing.Color.Salmon; 102 | this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 103 | this.label1.Location = new System.Drawing.Point(36, 61); 104 | this.label1.Name = "label1"; 105 | this.label1.Size = new System.Drawing.Size(170, 19); 106 | this.label1.TabIndex = 1; 107 | this.label1.Text = "Choose Sorting Algorithm"; 108 | this.label1.Click += new System.EventHandler(this.label1_Click); 109 | // 110 | // comboBox1 111 | // 112 | this.comboBox1.FormattingEnabled = true; 113 | this.comboBox1.Location = new System.Drawing.Point(24, 108); 114 | this.comboBox1.Name = "comboBox1"; 115 | this.comboBox1.Size = new System.Drawing.Size(182, 24); 116 | this.comboBox1.TabIndex = 2; 117 | this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); 118 | // 119 | // btnReset 120 | // 121 | this.btnReset.BackColor = System.Drawing.Color.Salmon; 122 | this.btnReset.FlatAppearance.BorderColor = System.Drawing.Color.Black; 123 | this.btnReset.FlatAppearance.BorderSize = 3; 124 | this.btnReset.FlatAppearance.MouseDownBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))); 125 | this.btnReset.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128))))); 126 | this.btnReset.Location = new System.Drawing.Point(12, 169); 127 | this.btnReset.Name = "btnReset"; 128 | this.btnReset.Size = new System.Drawing.Size(99, 28); 129 | this.btnReset.TabIndex = 3; 130 | this.btnReset.Text = "Reset"; 131 | this.btnReset.UseVisualStyleBackColor = false; 132 | this.btnReset.Click += new System.EventHandler(this.button1_Click); 133 | // 134 | // panel1 135 | // 136 | this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 137 | | System.Windows.Forms.AnchorStyles.Left) 138 | | System.Windows.Forms.AnchorStyles.Right))); 139 | this.panel1.BackColor = System.Drawing.SystemColors.ActiveCaptionText; 140 | this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; 141 | this.panel1.Location = new System.Drawing.Point(239, 0); 142 | this.panel1.Name = "panel1"; 143 | this.panel1.Size = new System.Drawing.Size(1080, 588); 144 | this.panel1.TabIndex = 4; 145 | this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint); 146 | // 147 | // button1 148 | // 149 | this.button1.BackColor = System.Drawing.Color.GreenYellow; 150 | this.button1.FlatAppearance.BorderColor = System.Drawing.Color.Black; 151 | this.button1.FlatAppearance.BorderSize = 3; 152 | this.button1.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green; 153 | this.button1.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); 154 | this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 155 | this.button1.ForeColor = System.Drawing.SystemColors.ControlText; 156 | this.button1.Location = new System.Drawing.Point(134, 169); 157 | this.button1.Name = "button1"; 158 | this.button1.Size = new System.Drawing.Size(99, 28); 159 | this.button1.TabIndex = 5; 160 | this.button1.Text = "Start Sort"; 161 | this.button1.UseVisualStyleBackColor = false; 162 | this.button1.Click += new System.EventHandler(this.button1_Click_1); 163 | // 164 | // btnPause 165 | // 166 | this.btnPause.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128))))); 167 | this.btnPause.ForeColor = System.Drawing.SystemColors.ControlText; 168 | this.btnPause.Location = new System.Drawing.Point(24, 222); 169 | this.btnPause.Name = "btnPause"; 170 | this.btnPause.Size = new System.Drawing.Size(209, 28); 171 | this.btnPause.TabIndex = 6; 172 | this.btnPause.Text = "Pause / Resume"; 173 | this.btnPause.UseVisualStyleBackColor = false; 174 | this.btnPause.Click += new System.EventHandler(this.btnPause_Click); 175 | // 176 | // Form1 177 | // 178 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 179 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 180 | this.BackColor = System.Drawing.Color.Lavender; 181 | this.ClientSize = new System.Drawing.Size(1331, 600); 182 | this.Controls.Add(this.btnPause); 183 | this.Controls.Add(this.button1); 184 | this.Controls.Add(this.panel1); 185 | this.Controls.Add(this.btnReset); 186 | this.Controls.Add(this.comboBox1); 187 | this.Controls.Add(this.label1); 188 | this.Controls.Add(this.menuStrip1); 189 | this.MainMenuStrip = this.menuStrip1; 190 | this.Name = "Form1"; 191 | this.Text = "Form1"; 192 | this.Load += new System.EventHandler(this.Form1_Load); 193 | this.menuStrip1.ResumeLayout(false); 194 | this.menuStrip1.PerformLayout(); 195 | this.ResumeLayout(false); 196 | this.PerformLayout(); 197 | 198 | } 199 | 200 | #endregion 201 | 202 | private System.Windows.Forms.MenuStrip menuStrip1; 203 | private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; 204 | private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; 205 | private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem; 206 | private System.Windows.Forms.Label label1; 207 | private System.Windows.Forms.ComboBox comboBox1; 208 | private System.Windows.Forms.Button btnReset; 209 | private System.Windows.Forms.Panel panel1; 210 | private System.Windows.Forms.ToolStripMenuItem contactMeToolStripMenuItem; 211 | private System.Windows.Forms.ToolStripMenuItem linkedinToolStripMenuItem; 212 | private System.Windows.Forms.Button button1; 213 | private System.Windows.Forms.Button btnPause; 214 | } 215 | } 216 | 217 | -------------------------------------------------------------------------------- /SortVisualizer/Form/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Windows.Forms; 8 | 9 | namespace SortVisualizer 10 | { 11 | public partial class Form1 : Form 12 | { 13 | 14 | int[] mainArray; 15 | Graphics g; 16 | BackgroundWorker w = null; 17 | bool isPaused = false; 18 | 19 | 20 | 21 | 22 | public Form1() 23 | { 24 | InitializeComponent(); 25 | PopulateDropdown(); 26 | } 27 | 28 | 29 | // List of Names of classes that implement the Sort Interface 30 | private void PopulateDropdown() 31 | { 32 | List classList = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()).Where(x => typeof(SortInterface).IsAssignableFrom(x) 33 | && !x.IsInterface && !x.IsAbstract).Select(x => x.Name).ToList(); 34 | classList.Sort(); 35 | foreach( string entry in classList) 36 | { 37 | comboBox1.Items.Add(entry); 38 | } 39 | comboBox1.SelectedIndex = 0; 40 | } 41 | 42 | private void button1_Click_1(object sender, EventArgs e) 43 | { 44 | if (mainArray == null) button1_Click(null, null); 45 | w = new BackgroundWorker(); 46 | w.WorkerSupportsCancellation = true; 47 | w.DoWork += new DoWorkEventHandler(w_DoWork); 48 | w.RunWorkerAsync(argument: comboBox1.SelectedItem); 49 | 50 | } 51 | 52 | 53 | private void exitToolStripMenuItem_Click(object sender, EventArgs e) 54 | { 55 | this.Close(); 56 | } 57 | 58 | private void label1_Click(object sender, EventArgs e) 59 | { 60 | 61 | } 62 | 63 | private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 64 | { 65 | 66 | } 67 | 68 | // Reset Button to generate the New Array 69 | private void button1_Click(object sender, EventArgs e) 70 | { 71 | g = panel1.CreateGraphics(); 72 | int NumEntries = panel1.Width; 73 | int MaxVal = panel1.Height; 74 | mainArray = new int[NumEntries]; 75 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Black), 0, 0, NumEntries, MaxVal); 76 | Random rand = new Random(); 77 | 78 | // Put Random Values into the Array 79 | for (int i = 0; i < NumEntries; i++) 80 | { 81 | mainArray[i] = rand.Next(0, MaxVal); 82 | 83 | } 84 | 85 | // Draw in Rectangles for the sorting array 86 | for (int i = 0; i < NumEntries; i++) 87 | { 88 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), i, MaxVal - mainArray[i], 1, MaxVal); 89 | } 90 | 91 | } 92 | 93 | private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) 94 | { 95 | 96 | } 97 | 98 | 99 | 100 | private void fileToolStripMenuItem_Click(object sender, EventArgs e) 101 | { 102 | 103 | } 104 | 105 | // Identigy class to get type of algortihm 106 | private void w_DoWork(object sender, DoWorkEventArgs e) 107 | { 108 | BackgroundWorker bw = sender as BackgroundWorker; 109 | string SortInterfaceName = (string)e.Argument; 110 | Type type = Type.GetType("SortVisualizer." + SortInterfaceName); 111 | var contructors = type.GetConstructors(); 112 | try 113 | { 114 | SortInterface s = (SortInterface)contructors[0].Invoke(new object[] { mainArray, g, panel1.Height }); 115 | while(!s.isSorted() && (!w.CancellationPending)) 116 | { 117 | s.nextStep(); 118 | } 119 | 120 | if (s.isSorted()) 121 | { 122 | s.completeSort(); 123 | } 124 | 125 | } 126 | catch(Exception ex) 127 | { 128 | } 129 | 130 | } 131 | 132 | private void btnPause_Click(object sender, EventArgs e) 133 | { 134 | if (!isPaused) 135 | { 136 | w.CancelAsync(); 137 | isPaused = true; 138 | } 139 | else 140 | { 141 | if (w.IsBusy) return; 142 | int NumEntires = panel1.Width; 143 | int MaxVal = panel1.Height; 144 | isPaused = false; 145 | for (int i = 0; i < NumEntires; i++) 146 | { 147 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Black), i, 0, 1, MaxVal); 148 | g.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Red), i, MaxVal - mainArray[i], 1, MaxVal); 149 | } 150 | w.RunWorkerAsync(argument: comboBox1.SelectedItem); 151 | 152 | 153 | } 154 | 155 | } 156 | 157 | private void panel1_Paint(object sender, PaintEventArgs e) 158 | { 159 | 160 | } 161 | 162 | private void Form1_Load(object sender, EventArgs e) 163 | { 164 | 165 | } 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /SortVisualizer/Form/Form1.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 25 125 | 126 | -------------------------------------------------------------------------------- /SortVisualizer/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace SortVisualizer 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SortVisualizer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SortVisualizer")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SortVisualizer")] 13 | [assembly: AssemblyCopyright("Copyright © 2020")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("177a9b98-ddf9-40d3-aac3-96ed95cdb476")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /SortVisualizer/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SortVisualizer.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SortVisualizer.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /SortVisualizer/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /SortVisualizer/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SortVisualizer.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /SortVisualizer/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SortVisualizer/SortInterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace SortVisualizer 9 | { 10 | interface SortInterface 11 | { 12 | void nextStep(); 13 | bool isSorted(); 14 | 15 | void reDraw(); 16 | 17 | void completeSort(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /SortVisualizer/SortVisualizer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {177A9B98-DDF9-40D3-AAC3-96ED95CDB476} 8 | WinExe 9 | SortVisualizer 10 | SortVisualizer 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Form 56 | 57 | 58 | Form1.cs 59 | 60 | 61 | 62 | 63 | 64 | Form1.cs 65 | 66 | 67 | ResXFileCodeGenerator 68 | Resources.Designer.cs 69 | Designer 70 | 71 | 72 | True 73 | Resources.resx 74 | 75 | 76 | SettingsSingleFileGenerator 77 | Settings.Designer.cs 78 | 79 | 80 | True 81 | Settings.settings 82 | True 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /resources/BubbleSort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haltaf19/Sorting-Visualizer/090af3c2bc6455d9e832116f330917e6c4795082/resources/BubbleSort.gif -------------------------------------------------------------------------------- /resources/InsertionSort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haltaf19/Sorting-Visualizer/090af3c2bc6455d9e832116f330917e6c4795082/resources/InsertionSort.gif -------------------------------------------------------------------------------- /resources/MergeSort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haltaf19/Sorting-Visualizer/090af3c2bc6455d9e832116f330917e6c4795082/resources/MergeSort.gif -------------------------------------------------------------------------------- /resources/SelectionSort.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haltaf19/Sorting-Visualizer/090af3c2bc6455d9e832116f330917e6c4795082/resources/SelectionSort.gif --------------------------------------------------------------------------------