├── .gitattributes ├── .gitignore ├── Binary_Search ├── Binary_Search.sln └── Binary_Search │ ├── App.config │ ├── BinaryArray.cs │ ├── Binary_Search.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── Bubble_Sorting ├── Bubble_Sort │ ├── App.config │ ├── Bubble_Sort.csproj │ ├── Program.cs │ └── Properties │ │ └── AssemblyInfo.cs └── Bubble_Sorting.sln ├── Files └── bubble.JPG ├── Insertio_Sort ├── Insertion_Sort.sln └── Insertion_Sorting │ ├── App.config │ ├── Insertion_Sorting.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── Merge_Sort ├── Merge_Sort.sln └── Merge_Sort_Exampe_Uses_Recursion │ ├── App.config │ ├── Merge_Sort_Exampe_Uses_Recursion.csproj │ ├── Program.cs │ └── Properties │ └── AssemblyInfo.cs ├── README.md └── Sorting_Library ├── Sorting_Library.sln ├── Sorting_Library ├── Properties │ └── AssemblyInfo.cs ├── Sorting_Library.csproj └── Sortings.cs └── Testing ├── App.config ├── Program.cs ├── Properties └── AssemblyInfo.cs └── Testing.csproj /.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 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /Binary_Search/Binary_Search.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Binary_Search", "Binary_Search\Binary_Search.csproj", "{04606A6B-3735-4401-A834-AA5B1542F52F}" 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 | {04606A6B-3735-4401-A834-AA5B1542F52F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {04606A6B-3735-4401-A834-AA5B1542F52F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {04606A6B-3735-4401-A834-AA5B1542F52F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {04606A6B-3735-4401-A834-AA5B1542F52F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Binary_Search/Binary_Search/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Binary_Search/Binary_Search/BinaryArray.cs: -------------------------------------------------------------------------------- 1 | namespace Binary_Search 2 | { 3 | using System; 4 | using static System.Console; 5 | class BinaryArray 6 | { 7 | private int[] data; 8 | private Random generator = new Random(); 9 | // Constructor 10 | public BinaryArray(int size) 11 | { 12 | 13 | data = new int[size]; 14 | for (int j = 0; j < data.Length; j++) 15 | { 16 | data[j] = generator.Next(10, 100); 17 | } 18 | 19 | } 20 | 21 | // Binary search perform. 22 | public int BinarySearch(int searchElement) 23 | { 24 | int low = 0, high = data.Length - 1, middle = (low + high) / 2, location = -1; 25 | do 26 | { 27 | Write(RemainingElements(low, high)); 28 | WriteLine(new string('-', 40)); 29 | if (searchElement == data[middle]) 30 | { 31 | location = middle; 32 | } 33 | else if (searchElement < data[middle]) 34 | { 35 | high = middle - 1; 36 | } 37 | else 38 | { 39 | low = middle + 1; 40 | } 41 | middle = (low + high + 1) / 2; 42 | 43 | } while ((low <= high) && (location == -1)); 44 | 45 | return location; 46 | } 47 | // shows which count elements remaining. 48 | public string RemainingElements(int low, int high) 49 | { 50 | string temporary = string.Empty; 51 | // output spaces alignment 52 | for (int i = 0; i < low; i++) 53 | { 54 | temporary += " "; 55 | } 56 | // output elements left in array 57 | for (int i = low; i <= high; i++) 58 | { 59 | temporary += data[i] + " "; 60 | } 61 | temporary += "\n"; 62 | return temporary; 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Binary_Search/Binary_Search/Binary_Search.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {04606A6B-3735-4401-A834-AA5B1542F52F} 8 | Exe 9 | Properties 10 | Binary_Search 11 | Binary_Search 12 | v4.5.2 13 | 512 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 | 61 | -------------------------------------------------------------------------------- /Binary_Search/Binary_Search/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Console; 3 | 4 | namespace Binary_Search 5 | { 6 | class Program 7 | { 8 | static void Main() 9 | { 10 | int searchInt; 11 | int position; 12 | BinaryArray searchArray = new BinaryArray(15); 13 | searchInt = int.Parse(ReadLine()); 14 | while (searchInt != -1) 15 | { 16 | // use binary search to try to find integer 17 | position = searchArray.BinarySearch(searchInt); 18 | 19 | // return value of -1 indicates integer was not found 20 | if (position == -1) 21 | { 22 | WriteLine("The integer {0} was not found.\n", searchInt); 23 | } 24 | else 25 | { 26 | WriteLine("The integer {0} was found in position {1}.\n", searchInt, position); 27 | } 28 | 29 | // Prompt and input next int from user 30 | WriteLine("Enter an integer value (-1 to quit): "); 31 | searchInt = Convert.ToInt32(Console.ReadLine()); 32 | WriteLine(); 33 | 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Binary_Search/Binary_Search/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("Binary_Search")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Binary_Search")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("04606a6b-3735-4401-a834-aa5b1542f52f")] 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 | -------------------------------------------------------------------------------- /Bubble_Sorting/Bubble_Sort/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Bubble_Sorting/Bubble_Sort/Bubble_Sort.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {C5DA5DAA-438F-4502-A68D-C14EC880263F} 8 | Exe 9 | Properties 10 | Bubble_Sort 11 | Bubble_Sort 12 | v4.5.2 13 | 512 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 | 60 | -------------------------------------------------------------------------------- /Bubble_Sorting/Bubble_Sort/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using static System.Console; 3 | namespace Bubble_Sort 4 | { 5 | class Program 6 | { 7 | static void Main() 8 | { 9 | int[] a = { 12, 4, 5, 3, 4, 5, 6, 6, 76, 7, 78, 2, 5, 6, 7 }; 10 | Bubble(ref a); 11 | foreach (var i in a) 12 | { 13 | WriteLine(i); 14 | } 15 | int[] arr = RandomArray(20); 16 | PadLeft(ref arr, 5); 17 | 18 | } 19 | 20 | public static void Bubble(ref int[] array) 21 | { 22 | int temp = 0; 23 | 24 | for (int i = 0; i < array.Length; i++) 25 | { 26 | for (int j = 0; j < array.Length - 1; j++) 27 | { 28 | if (array[j] > array[j + 1]) 29 | { 30 | Swap(ref array[j], ref array[j + 1]); 31 | } 32 | } 33 | } 34 | } 35 | 36 | public static void Swap(ref int x, ref int y) 37 | { 38 | int temp = x; 39 | x = y; 40 | y = temp; 41 | } 42 | 43 | public static void Exchange(ref int[] arr, int first, int end) 44 | { 45 | if (first < 0 || end < 0) 46 | { 47 | WriteLine("Not correct indexes were inputed"); 48 | } 49 | if (first > arr.Length || end > arr.Length) 50 | { 51 | WriteLine("The sended parameters {0} and {1} are out of range", first, end); 52 | return; 53 | } 54 | int temp = arr[first]; 55 | arr[first] = arr[end]; 56 | arr[end] = temp; 57 | } 58 | 59 | #region Generate Random Array 60 | // returns without ref. 61 | public static int[] RandomArray(int length) 62 | { 63 | Random rd = new Random(); 64 | int[] arr = new int[length]; 65 | for (int i = 0; i < arr.Length; i++) 66 | { 67 | arr[i] = rd.Next(int.MinValue, int.MaxValue); 68 | } 69 | return arr; 70 | } 71 | // Returns with ref 72 | public static void RandomArray(ref int[] arr) 73 | { 74 | Random rd = new Random(); 75 | for (int i = 0; i < arr.Length; i++) 76 | { 77 | arr[i] = rd.Next(int.MinValue, int.MaxValue); 78 | } 79 | } 80 | #endregion 81 | public static void PadLeft(ref int[] arr, int howmanytimes) 82 | { 83 | while (howmanytimes != 0) 84 | { 85 | int temp = arr[0]; 86 | 87 | for (int i = 0; i <= arr.Length; i++) 88 | { 89 | if (i == arr.Length - 1) 90 | { 91 | arr[i] = temp; 92 | break; 93 | } 94 | arr[i] = arr[i + 1]; 95 | } 96 | howmanytimes--; 97 | } 98 | } 99 | 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Bubble_Sorting/Bubble_Sort/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("Bubble_Sort")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Bubble_Sort")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("c5da5daa-438f-4502-a68d-c14ec880263f")] 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 | -------------------------------------------------------------------------------- /Bubble_Sorting/Bubble_Sorting.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bubble_Sort", "Bubble_Sort\Bubble_Sort.csproj", "{C5DA5DAA-438F-4502-A68D-C14EC880263F}" 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 | {C5DA5DAA-438F-4502-A68D-C14EC880263F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C5DA5DAA-438F-4502-A68D-C14EC880263F}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C5DA5DAA-438F-4502-A68D-C14EC880263F}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C5DA5DAA-438F-4502-A68D-C14EC880263F}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Files/bubble.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/narekye/Sorting_Library/8a88bd0b4ea0effc9050800188fd19f81cecb602/Files/bubble.JPG -------------------------------------------------------------------------------- /Insertio_Sort/Insertion_Sort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Insertion_Sorting", "Insertion_Sorting\Insertion_Sorting.csproj", "{859AF954-4C51-49CF-9B0C-52C38EA06D62}" 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 | {859AF954-4C51-49CF-9B0C-52C38EA06D62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {859AF954-4C51-49CF-9B0C-52C38EA06D62}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {859AF954-4C51-49CF-9B0C-52C38EA06D62}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {859AF954-4C51-49CF-9B0C-52C38EA06D62}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Insertio_Sort/Insertion_Sorting/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Insertio_Sort/Insertion_Sorting/Insertion_Sorting.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {859AF954-4C51-49CF-9B0C-52C38EA06D62} 8 | Exe 9 | Properties 10 | Insertion_Sorting 11 | Insertion_Sorting 12 | v4.5.2 13 | 512 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 | 60 | -------------------------------------------------------------------------------- /Insertio_Sort/Insertion_Sorting/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | namespace Insertion_Sorting 4 | { 5 | class Program 6 | { 7 | static void Main() 8 | { 9 | // Perform insertion sorting example on generic method. 10 | // Just for example :) 11 | int[] array = { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 3, 4, 4, 5, 5, 56434, 5423, 423423, 4, 234, 234, 545, 343 }; 12 | PerformInsertionSort(array); 13 | foreach (var i in array) 14 | { 15 | Console.WriteLine(i); 16 | } 17 | } 18 | 19 | static void PerformInsertionSort(T[] inputarray, Comparer comparer = null) 20 | { 21 | var equalityComparer = comparer ?? Comparer.Default; 22 | for (int counter = 0; counter < inputarray.Length - 1; counter++) 23 | { 24 | int index = counter + 1; 25 | while (index > 0) 26 | { 27 | // if we change the statement to .... < 0 it will sorted by descending. 28 | if (equalityComparer.Compare(inputarray[index - 1], inputarray[index]) > 0) 29 | { 30 | T temp = inputarray[index - 1]; 31 | inputarray[index - 1] = inputarray[index]; 32 | inputarray[index] = temp; 33 | } 34 | index--; 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Insertio_Sort/Insertion_Sorting/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("Insertion_Sorting")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Insertion_Sorting")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("859af954-4c51-49cf-9b0c-52c38ea06d62")] 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 | -------------------------------------------------------------------------------- /Merge_Sort/Merge_Sort.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge_Sort_Exampe_Uses_Recursion", "Merge_Sort_Exampe_Uses_Recursion\Merge_Sort_Exampe_Uses_Recursion.csproj", "{B90D4EA8-81B8-48A1-910B-EB7DD958F8F2}" 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 | {B90D4EA8-81B8-48A1-910B-EB7DD958F8F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B90D4EA8-81B8-48A1-910B-EB7DD958F8F2}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B90D4EA8-81B8-48A1-910B-EB7DD958F8F2}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B90D4EA8-81B8-48A1-910B-EB7DD958F8F2}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Merge_Sort/Merge_Sort_Exampe_Uses_Recursion/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Merge_Sort/Merge_Sort_Exampe_Uses_Recursion/Merge_Sort_Exampe_Uses_Recursion.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {B90D4EA8-81B8-48A1-910B-EB7DD958F8F2} 8 | Exe 9 | Properties 10 | Merge_Sort_Exampe_Uses_Recursion 11 | Merge_Sort_Exampe_Uses_Recursion 12 | v4.5.2 13 | 512 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 | 60 | -------------------------------------------------------------------------------- /Merge_Sort/Merge_Sort_Exampe_Uses_Recursion/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | #pragma warning disable 219 5 | 6 | namespace Merge_Sort_Exampe_Uses_Recursion 7 | { 8 | class Program 9 | { 10 | static void Main() 11 | { 12 | int[] array = new int[10000]; 13 | Random rd = new Random(); 14 | for (int i = 0; i < array.Length; i++) 15 | { 16 | array[i] = rd.Next(0, int.MaxValue); 17 | } 18 | Stopwatch timer = new Stopwatch(); 19 | timer.Start(); 20 | MergeSort(array); 21 | timer.Stop(); 22 | Console.WriteLine(timer.Elapsed); 23 | Console.Read(); 24 | } 25 | 26 | static void MergeSort(int[] array) 27 | { 28 | if (array.Length <= 1) return; 29 | 30 | int leftsize = array.Length / 2; 31 | int rightsize = array.Length - leftsize; 32 | 33 | int[] left = new int[leftsize]; 34 | int[] right = new int[rightsize]; 35 | 36 | Array.Copy(array, 0, left, 0, leftsize); 37 | Array.Copy(array, leftsize, right, 0, rightsize); 38 | 39 | MergeSort(left); 40 | MergeSort(right); 41 | 42 | Merge(array, left, right); 43 | } 44 | 45 | static void Merge(int[] array, int[] left, int[] right) 46 | { 47 | int leftindex = 0, rigthindex = 0, target = 0; 48 | int remaining = left.Length + right.Length; 49 | 50 | while (remaining > 0) 51 | { 52 | if (leftindex >= left.Length) 53 | { 54 | array[target] = right[rigthindex++]; 55 | } 56 | else if (rigthindex >= right.Length) 57 | { 58 | array[target] = left[leftindex++]; 59 | } 60 | 61 | else if (left[leftindex].CompareTo(right[rigthindex]) < 0) 62 | { 63 | array[target] = left[leftindex++]; 64 | } 65 | else 66 | { 67 | array[target] = right[rigthindex++]; 68 | } 69 | 70 | target++; 71 | remaining--; 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Merge_Sort/Merge_Sort_Exampe_Uses_Recursion/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("Merge_Sort_Exampe_Uses_Recursion")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Merge_Sort_Exampe_Uses_Recursion")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("b90d4ea8-81b8-48a1-910b-eb7dd958f8f2")] 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # C# 6.0 Visual Studio 2015 Enterprice edition with .NET Framework 4.6 2 | 3 | Sorting examples on C#. 4 | ## Attention all extension methods are generic and including their summary, and it seen by intellisense. :v: 5 | 6 | Sorting library with generics -> [Download](https://codeload.github.com/narekye/Sorting_Examples/zip/master)
7 |
8 | 9 | [Bubble sorting](https://github.com/narekye/Sorting_Examples/tree/master/Bubble_Sorting)
10 | [Binary search](https://github.com/narekye/Sorting_Examples/tree/master/Binary_Search)
11 | [Insertion sort](https://github.com/narekye/Sorting_Examples/tree/master/Insertio_Sort)
12 | [Merge sort](https://github.com/narekye/Sorting_Examples/tree/master/Merge_Sort)
13 |
14 | -------------------------------------------------------------------------------- /Sorting_Library/Sorting_Library.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sorting_Library", "Sorting_Library\Sorting_Library.csproj", "{C6C56894-9E12-40A3-8612-A99FCB3DFB9E}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testing", "Testing\Testing.csproj", "{A8207F26-1F48-4CFB-A493-04D211D07396}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {C6C56894-9E12-40A3-8612-A99FCB3DFB9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {C6C56894-9E12-40A3-8612-A99FCB3DFB9E}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {C6C56894-9E12-40A3-8612-A99FCB3DFB9E}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {C6C56894-9E12-40A3-8612-A99FCB3DFB9E}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {A8207F26-1F48-4CFB-A493-04D211D07396}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {A8207F26-1F48-4CFB-A493-04D211D07396}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {A8207F26-1F48-4CFB-A493-04D211D07396}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {A8207F26-1F48-4CFB-A493-04D211D07396}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Sorting_Library/Sorting_Library/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("Sorting_Library")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Sorting_Library")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("c6c56894-9e12-40a3-8612-a99fcb3dfb9e")] 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 | -------------------------------------------------------------------------------- /Sorting_Library/Sorting_Library/Sorting_Library.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {C6C56894-9E12-40A3-8612-A99FCB3DFB9E} 8 | Library 9 | Properties 10 | Sorting_Library 11 | Sorting_Library 12 | v4.5.2 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | DEBUG;TRACE 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | -------------------------------------------------------------------------------- /Sorting_Library/Sorting_Library/Sortings.cs: -------------------------------------------------------------------------------- 1 | namespace Sorting_Library 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | /// 7 | /// Perform own sorting algorithm with extension methods 8 | /// Generic types included to all algorithms. 9 | /// 10 | public static class Sortings 11 | { 12 | /// 13 | /// Bubble Sorting, best and worst cases pasted in text below for Big - O 14 | /// Hardest: O(n) , O(n^2) , O(n^2) 15 | /// Memory: O(1) , O(1) , O(1) 16 | /// 17 | /// 18 | /// 19 | /// void 20 | #region Bubble 21 | public static void PerformBubbleSort(this T[] array) 22 | { 23 | var equalityComparer = Comparer.Default; 24 | for (int i = 0; i < array.Length; i++) 25 | { 26 | for (int j = 0; j < array.Length - 1; j++) 27 | { 28 | if (equalityComparer.Compare(array[j], array[j + 1]) > 0) // array[j] > array[j + 1] 29 | { 30 | Swap(ref array[j], ref array[j + 1]); 31 | } 32 | } 33 | } 34 | } 35 | 36 | private static void Swap(ref T x, ref T y) 37 | { 38 | Comparer comparer = Comparer.Default; 39 | if (comparer.Compare(x, y) == 0) return; 40 | T temp = x; 41 | x = y; 42 | y = temp; 43 | } 44 | #endregion Bubble 45 | 46 | /// 47 | /// Insertion Sorting, best and worst cases pasted in text below for Big - O 48 | /// Hardest: O(n) , O(n^2) , O(n^2) 49 | /// Memory: O(1) , O(1) , O(1) 50 | /// 51 | /// 52 | /// 53 | /// void 54 | #region Insertion 55 | public static void PerformInsertionSort(this T[] array, Comparer comparer = null) 56 | { 57 | var equalityComparer = comparer ?? Comparer.Default; 58 | for (int counter = 0; counter < array.Length - 1; counter++) 59 | { 60 | int index = counter + 1; 61 | while (index > 0) 62 | { 63 | // if we change the statement to .... < 0 it will sorted by descending. 64 | if (equalityComparer.Compare(array[index - 1], array[index]) > 0) 65 | { 66 | T temp = array[index - 1]; 67 | array[index - 1] = array[index]; 68 | array[index] = temp; 69 | } 70 | index--; 71 | } 72 | } 73 | } 74 | #endregion 75 | 76 | /// 77 | /// Merge Sorting, best and worst cases pasted in text below for Big - O 78 | /// Using recursion for cutting the array to subarrays. 79 | /// Hardest: O(n log n) , O(n log n) , O(n log n) 80 | /// Memory: O(n) , O(n) , O(n) 81 | /// 82 | /// 83 | /// 84 | /// void 85 | #region Merge 86 | 87 | public static void PerformMergeSort(this T[] array) 88 | { 89 | if (array.Length <= 1) return; 90 | 91 | int leftsize = array.Length / 2; 92 | int rightsize = array.Length - leftsize; 93 | 94 | T[] left = new T[leftsize]; 95 | T[] right = new T[rightsize]; 96 | 97 | Array.Copy(array, 0, left, 0, leftsize); 98 | Array.Copy(array, leftsize, right, 0, rightsize); 99 | 100 | PerformMergeSort(left); 101 | PerformMergeSort(right); 102 | 103 | Merge(array, left, right); 104 | } 105 | 106 | private static void Merge(T[] array, T[] left, T[] right, Comparer comparer = null) 107 | { 108 | var equalitycomparer = comparer ?? Comparer.Default; 109 | int leftindex = 0, rigthindex = 0, target = 0; 110 | int remaining = left.Length + right.Length; 111 | 112 | while (remaining > 0) 113 | { 114 | if (leftindex >= left.Length) 115 | { 116 | array[target] = right[rigthindex++]; 117 | } 118 | else if (rigthindex >= right.Length) 119 | { 120 | array[target] = left[leftindex++]; 121 | } 122 | 123 | else if (equalitycomparer.Compare(left[leftindex], right[rigthindex]) < 0) 124 | { 125 | array[target] = left[leftindex++]; 126 | } 127 | else 128 | { 129 | array[target] = right[rigthindex++]; 130 | } 131 | 132 | target++; 133 | remaining--; 134 | } 135 | } 136 | #endregion 137 | 138 | /// 139 | /// Selection Sorting, best and worst cases pasted in text below for Big - O 140 | /// Hardest: O(n) , O(n^2) , O(n^2) 141 | /// Memory: O(1) , O(1) , O(1) 142 | /// 143 | /// 144 | /// 145 | /// void 146 | #region Selection 147 | public static void PerformSelectionSort(this T[] array) 148 | { 149 | int sortedRangeEnd = 0; 150 | while (sortedRangeEnd < array.Length) 151 | { 152 | int nextSmallestIndex = FindIndex(array, sortedRangeEnd); 153 | Swap(array, sortedRangeEnd, nextSmallestIndex); 154 | sortedRangeEnd++; 155 | } 156 | } 157 | 158 | private static void Swap(T[] array, int left, int right) 159 | { 160 | if (left == right) return; 161 | T temp = array[left]; 162 | array[left] = array[right]; 163 | array[right] = temp; 164 | 165 | } 166 | private static int FindIndex(T[] array, int index) 167 | { 168 | Comparer equality = Comparer.Default; 169 | T current = array[index]; 170 | int currentindex = index; 171 | for (int i = index + 1; i < array.Length; i++) 172 | { 173 | if (equality.Compare(current, array[i]) > 0) 174 | { 175 | current = array[i]; 176 | currentindex = i; 177 | } 178 | } 179 | return currentindex; 180 | } 181 | #endregion 182 | 183 | /// 184 | /// 185 | /// 186 | /// 187 | /// 188 | #region Quick 189 | public static void PerformQuickSort(this T[] array) { } 190 | #endregion 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /Sorting_Library/Testing/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Sorting_Library/Testing/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Sorting_Library; 3 | 4 | namespace Testing 5 | { 6 | class Program 7 | { 8 | static void Main() 9 | { 10 | int[] arr = { 3, 1, 3, 4, 6, 2, 3, 1, 4, 4 }; 11 | arr.PerformBubbleSort(); 12 | arr.PerformSelectionSort(); 13 | arr.PerformInsertionSort(); 14 | arr.PerformMergeSort(); 15 | foreach (int i in arr) 16 | { 17 | Console.WriteLine(i); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sorting_Library/Testing/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("Testing")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Testing")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("a8207f26-1f48-4cfb-a493-04d211d07396")] 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 | -------------------------------------------------------------------------------- /Sorting_Library/Testing/Testing.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {A8207F26-1F48-4CFB-A493-04D211D07396} 8 | Exe 9 | Properties 10 | Testing 11 | Testing 12 | v4.5.2 13 | 512 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 | {c6c56894-9e12-40a3-8612-a99fcb3dfb9e} 55 | Sorting_Library 56 | 57 | 58 | 59 | 66 | --------------------------------------------------------------------------------