Skip to content

Commit 1baac8a

Browse files
committed
CombSort 1.0
1 parent 05c090f commit 1baac8a

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

CombSort/Class1.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace SortingAlgos
5+
{
6+
public class CombSort
7+
{
8+
private static bool sorted;
9+
10+
public static void Sort(int[] input)
11+
{
12+
double gap = input.Length;
13+
double shrink = 1.3;
14+
15+
while (sorted == false)
16+
{
17+
gap = Math.Floor(gap / shrink);
18+
if (gap > 1)
19+
{
20+
sorted = false;
21+
}
22+
else
23+
{
24+
gap = 1;
25+
sorted = true;
26+
}
27+
28+
for (int i = 0; i + gap < input.Length; i++)
29+
{
30+
if (input[i] > input[i + 1])
31+
{
32+
int temp = input[i + 1];
33+
input[i + 1] = input[i];
34+
input[i] = temp;
35+
sorted = false;
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}

CombSort/CombSort.csproj

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{47E8BBB7-42BC-4216-AFC5-357FEF67B401}</ProjectGuid>
8+
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>CombSort</RootNamespace>
12+
<AssemblyName>CombSort</AssemblyName>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System"/>
37+
<Reference Include="System.Core"/>
38+
<Reference Include="System.Data"/>
39+
<Reference Include="System.Xml"/>
40+
</ItemGroup>
41+
<ItemGroup>
42+
<Compile Include="Class1.cs" />
43+
<Compile Include="Properties\AssemblyInfo.cs" />
44+
</ItemGroup>
45+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
46+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
47+
Other similar extension points exist, see Microsoft.Common.targets.
48+
<Target Name="BeforeBuild">
49+
</Target>
50+
<Target Name="AfterBuild">
51+
</Target>
52+
-->
53+
54+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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("CombSort")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("CombSort")]
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("47E8BBB7-42BC-4216-AFC5-357FEF67B401")]
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")]

SortingAlgos.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BubbleSort", "BubbleSort\Bu
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShakerSort", "ShakerSort\ShakerSort.csproj", "{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CombSort", "CombSort\CombSort.csproj", "{47E8BBB7-42BC-4216-AFC5-357FEF67B401}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
2729
{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
2830
{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
2931
{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{47E8BBB7-42BC-4216-AFC5-357FEF67B401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{47E8BBB7-42BC-4216-AFC5-357FEF67B401}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{47E8BBB7-42BC-4216-AFC5-357FEF67B401}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{47E8BBB7-42BC-4216-AFC5-357FEF67B401}.Release|Any CPU.Build.0 = Release|Any CPU
3036
EndGlobalSection
3137
GlobalSection(SolutionProperties) = preSolution
3238
HideSolutionNode = FALSE

SortingAlgos/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public static void Main(string[] args)
6565
ShakerSort.Sort(array);
6666
ArrayEqual(array, sortedArray);
6767
Console.WriteLine("ShakerSort finished");
68+
69+
// Generate some random numbers
70+
GenerateArray(array, sortedArray, rnd, arraySizes);
71+
72+
// Complete BubbleSort test
73+
CombSort.Sort(array);
74+
ArrayEqual(array, sortedArray);
75+
Console.WriteLine("CombSort finished");
6876
}
6977
}
7078
}

SortingAlgos/SortingAlgos.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
<Project>{580ff020-9a74-45c3-8709-1f76cc8bea23}</Project>
5050
<Name>BubbleSort</Name>
5151
</ProjectReference>
52+
<ProjectReference Include="..\CombSort\CombSort.csproj">
53+
<Project>{47e8bbb7-42bc-4216-afc5-357fef67b401}</Project>
54+
<Name>CombSort</Name>
55+
</ProjectReference>
5256
<ProjectReference Include="..\ShakerSort\ShakerSort.csproj">
5357
<Project>{52b16d6c-af38-42a4-bf8f-ff42c8bbd0a1}</Project>
5458
<Name>ShakerSort</Name>

0 commit comments

Comments
 (0)