Skip to content

Commit

Permalink
ShakerSort 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
1byte2bytes committed Sep 18, 2017
1 parent 4d7f5f7 commit 4f47956
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 5,8 @@ A set of sorting algorithms I made in C#. I don't know why you'd really use thes

## Implemented Algorithms
- Bubble Sort
- Shaker Sort

## Algorithms coming soon
- Shellsort
- Combsort
- Shakersort
- Shell sort
- Comb sort
52 changes: 52 additions & 0 deletions ShakerSort/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 1,52 @@
using System;

namespace SortingAlgos
{
public class ShakerSort
{
public static void Sort(int[] input)
{
int len = input.Length;
bool swapped = true;

while (swapped == true)
{
swapped = false;

for (int i = 0; i < len - 2; i )
{
if (input[i] > input[i 1])
{
int temp = input[i 1];
input[i 1] = input[i];
input[i] = temp;
swapped = true;
}
}

if (swapped == false)
{
return;
}

swapped = false;

for (int i = len - 2; i > 0; i--)
{
if (input[i] > input[i 1])
{
int temp = input[i 1];
input[i 1] = input[i];
input[i] = temp;
swapped = true;
}
}

if (swapped == false)
{
return;
}
}
}
}
}
36 changes: 36 additions & 0 deletions ShakerSort/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("ShakerSort")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShakerSort")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[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("52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1")]

// 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")]
54 changes: 54 additions & 0 deletions ShakerSort/ShakerSort.csproj
Original file line number Diff line number Diff line change
@@ -0,0 1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" 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>{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ShakerSort</RootNamespace>
<AssemblyName>ShakerSort</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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.Data"/>
<Reference Include="System.Xml"/>
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

</Project>
6 changes: 6 additions & 0 deletions SortingAlgos.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SortingAlgos", "SortingAlgo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BubbleSort", "BubbleSort\BubbleSort.csproj", "{580FF020-9A74-45C3-8709-1F76CC8BEA23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShakerSort", "ShakerSort\ShakerSort.csproj", "{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 23,10 @@ Global
{580FF020-9A74-45C3-8709-1F76CC8BEA23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{580FF020-9A74-45C3-8709-1F76CC8BEA23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{580FF020-9A74-45C3-8709-1F76CC8BEA23}.Release|Any CPU.Build.0 = Release|Any CPU
{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52B16D6C-AF38-42A4-BF8F-FF42C8BBD0A1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 16 additions & 6 deletions SortingAlgos/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 14,19 @@ public static void GenerateArray(int[] array, int[] sortedArray, Random rnd, int
{
array[i] = rnd.Next();
}
Console.WriteLine("-------------------------");
Console.WriteLine("Generated random numbers!");

// Copy and sort array
Array.Copy(array, sortedArray, arraySizes);
Array.Sort(sortedArray);

// Check if generated numbers are the same as the sorted array
if (ArrayEqual(array, sortedArray) == false)
{
Console.WriteLine("Done checking numbers");
Console.WriteLine("-------------------------");
}
}

public static bool ArrayEqual(int[] first, int[] second)
Expand All @@ -45,16 53,18 @@ public static void Main(string[] args)
// Generate some random numbers
GenerateArray(array, sortedArray, rnd, arraySizes);

// Check that the sorted array and main array are not equal
if (ArrayEqual(array, sortedArray) == false)
{
Console.WriteLine("Done checking numbers");
}

// Complete BubbleSort test
BubbleSort.Sort(array);
ArrayEqual(array, sortedArray);
Console.WriteLine("BubbleSort finished");

// Generate some random numbers
GenerateArray(array, sortedArray, rnd, arraySizes);

// Complete BubbleSort test
ShakerSort.Sort(array);
ArrayEqual(array, sortedArray);
Console.WriteLine("ShakerSort finished");
}
}
}
4 changes: 4 additions & 0 deletions SortingAlgos/SortingAlgos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 49,10 @@
<Project>{580ff020-9a74-45c3-8709-1f76cc8bea23}</Project>
<Name>BubbleSort</Name>
</ProjectReference>
<ProjectReference Include="..\ShakerSort\ShakerSort.csproj">
<Project>{52b16d6c-af38-42a4-bf8f-ff42c8bbd0a1}</Project>
<Name>ShakerSort</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit 4f47956

Please sign in to comment.