Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shell sort #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions ShellSort/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ShellSort")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShellSort")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a6af49ea-7c5e-4265-b1d4-845788389f63")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
48 changes: 48 additions & 0 deletions ShellSort/ShellSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shellsort
{
public class ShellSort
{
private readonly int[] _array;

public ShellSort(int[] array)
{
this._array = array;
}

public int[] Sort()
{
int i, j, inc, temp;
var array_size = _array.Length;
inc = 3;

while (inc > 0)
{
for (i = 0; i < array_size; i++)
{
j = i;
temp = _array[i];
while ((j >= inc) && (_array[j - inc] > temp))
{
_array[j] = _array[j - inc];
j = j - inc;
}
_array[j] = temp;
}
if (inc / 2 != 0)
inc = inc / 2;
else if (inc == 1)
inc = 0;
else
inc = 1;
}

return _array;
}
}
}
48 changes: 48 additions & 0 deletions ShellSort/ShellSort.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A6AF49EA-7C5E-4265-B1D4-845788389F63}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ShellSort</RootNamespace>
<AssemblyName>ShellSort</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ShellSort.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
18 changes: 5 additions & 13 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="interpolationsearch">
<HintPath>..\interpolationsearch\bin\Debug\interpolationsearch.dll</HintPath>
</Reference>
<Reference Include="jumpsearch">
<HintPath>..\jumpsearch\bin\Debug\jumpsearch.dll</HintPath>
</Reference>
<Reference Include="linearsearch">
<HintPath>..\linearsearch\bin\Debug\linearsearch.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
Expand All @@ -60,9 +50,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="FibonacciSearchTest.cs" />
<Compile Include="search\JumpSearchTest.cs" />
<Compile Include="search\LinearsearchTest.cs" />
<Compile Include="search\InterpolationSearchTest.cs" />
<Compile Include="sort\QuickSortTests.cs" />
<Compile Include="greedy\BellmanFordAlgorithmTests.cs" />
<Compile Include="sort\BogoSortTests.cs" />
Expand All @@ -73,6 +60,7 @@
<Compile Include="sort\HeapSortTests.cs" />
<Compile Include="sort\CountingSortTests.cs" />
<Compile Include="sort\SelectionsortTests.cs" />
<Compile Include="sort\ShellSortTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down Expand Up @@ -118,6 +106,10 @@
<Project>{A9022928-E9E9-45BE-BFEC-85A1A870A7EB}</Project>
<Name>selectionsort</Name>
</ProjectReference>
<ProjectReference Include="..\ShellSort\ShellSort.csproj">
<Project>{a6af49ea-7c5e-4265-b1d4-845788389f63}</Project>
<Name>ShellSort</Name>
</ProjectReference>
<ProjectReference Include="..\sort\heapsort\heapsort.csproj">
<Project>{ceab3173-99c9-4f09-aee2-d31152d4270d}</Project>
<Name>heapsort</Name>
Expand Down
29 changes: 0 additions & 29 deletions Tests/search/ExponentialSearchTests.cs

This file was deleted.

35 changes: 0 additions & 35 deletions Tests/search/InterpolationSearchTest.cs

This file was deleted.

35 changes: 0 additions & 35 deletions Tests/search/JumpSearchTest.cs

This file was deleted.

34 changes: 0 additions & 34 deletions Tests/search/LinearsearchTest.cs

This file was deleted.

27 changes: 27 additions & 0 deletions Tests/sort/ShellSortTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using shellsort;

namespace Tests.sort
{
[TestClass]
public class ShellSortTests
{
[TestMethod]
public void SortNormally()
{
var array = new[] { 25, 17, 49, 1, 195, 58 };

var shellSort = new ShellSort(array);

var result = shellSort.Sort().ToList();

Assert.AreEqual(1, result.First());
Assert.AreEqual(195, result.Last());
}
}
}
11 changes: 9 additions & 2 deletions csharp-algorithms.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2019
# Visual Studio Version 16
VisualStudioVersion = 16.0.29230.47
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp-algorithms", "csharp-algorithms\csharp-algorithms.csproj", "{3511528E-8696-40B8-85AB-97456347A497}"
EndProject
Expand Down Expand Up @@ -33,6 +33,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "knapsackproblem", "knapsack
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bellmanFordAlgorithm", "bellmanFordAlgorithm\bellmanFordAlgorithm.csproj", "{6B79C9EC-0219-44AD-B399-CD4046718E66}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShellSort", "ShellSort\ShellSort.csproj", "{A6AF49EA-7C5E-4265-B1D4-845788389F63}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -87,6 +89,10 @@ Global
{6B79C9EC-0219-44AD-B399-CD4046718E66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B79C9EC-0219-44AD-B399-CD4046718E66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B79C9EC-0219-44AD-B399-CD4046718E66}.Release|Any CPU.Build.0 = Release|Any CPU
{A6AF49EA-7C5E-4265-B1D4-845788389F63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6AF49EA-7C5E-4265-B1D4-845788389F63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6AF49EA-7C5E-4265-B1D4-845788389F63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6AF49EA-7C5E-4265-B1D4-845788389F63}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -102,6 +108,7 @@ Global
{8087DFD2-673A-499F-B130-0FAE0F31EADC} = {05BBB622-53C5-4866-869B-B45978502CB5}
{8870FC35-4386-43E5-B5EA-1C764E7ADC54} = {05BBB622-53C5-4866-869B-B45978502CB5}
{6B79C9EC-0219-44AD-B399-CD4046718E66} = {05BBB622-53C5-4866-869B-B45978502CB5}
{A6AF49EA-7C5E-4265-B1D4-845788389F63} = {6A9C8607-AA57-4817-B2C8-B8DD5065AC7C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7F2BFC66-A9D6-4C6D-A15A-984F23C11D29}
Expand Down