mirror of https://github.com/icsharpcode/ILSpy.git
7 changed files with 134 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||||||
|
#region Using directives
|
||||||
|
|
||||||
|
using System.Reflection; |
||||||
|
using System.Runtime.CompilerServices; |
||||||
|
using System.Runtime.InteropServices; |
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
// 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("QuickSort")] |
||||||
|
[assembly: AssemblyDescription("")] |
||||||
|
[assembly: AssemblyConfiguration("")] |
||||||
|
[assembly: AssemblyCompany("")] |
||||||
|
[assembly: AssemblyProduct("QuickSort")] |
||||||
|
[assembly: AssemblyCopyright("")] |
||||||
|
[assembly: AssemblyTrademark("")] |
||||||
|
[assembly: AssemblyCulture("")] |
||||||
|
|
||||||
|
// This sets the default COM visibility of types in the assembly to invisible.
|
||||||
|
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||||
|
[assembly: ComVisible(false)] |
||||||
|
|
||||||
|
// The assembly version has following format :
|
||||||
|
//
|
||||||
|
// Major.Minor.Build.Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can use the default the Revision and
|
||||||
|
// Build Numbers by using the '*' as shown below:
|
||||||
|
[assembly: AssemblyVersion("1.0.*")] |
@ -0,0 +1,49 @@ |
|||||||
|
static class QuickSortProgram |
||||||
|
{ |
||||||
|
public static void Main(string[] args) |
||||||
|
{ |
||||||
|
int[] intArray = new int[args.Length]; |
||||||
|
for (int i = 0; i < intArray.Length; i++) { |
||||||
|
intArray[i] = int.Parse(args[i]); |
||||||
|
} |
||||||
|
QuickSort(intArray, 0, intArray.Length - 1); |
||||||
|
for (int i = 0; i < intArray.Length; i++) { |
||||||
|
System.Console.Write(intArray[i].ToString() + " "); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// For description of this algorithm see:
|
||||||
|
/// http://en.wikipedia.org/wiki/Quick_sort
|
||||||
|
public static void QuickSort(int[] array, int left, int right) |
||||||
|
{ |
||||||
|
if (right > left) { |
||||||
|
int pivotIndex = (left + right) / 2; |
||||||
|
int pivotNew = Partition(array, left, right, pivotIndex); |
||||||
|
QuickSort(array, left, pivotNew - 1); |
||||||
|
QuickSort(array, pivotNew + 1, right); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static int Partition(int[] array, int left, int right, |
||||||
|
int pivotIndex) |
||||||
|
{ |
||||||
|
int pivotValue = array[pivotIndex]; |
||||||
|
Swap(array, pivotIndex, right); |
||||||
|
int storeIndex = left; |
||||||
|
for(int i = left; i < right; i++) { |
||||||
|
if (array[i] <= pivotValue) { |
||||||
|
Swap(array, storeIndex, i); |
||||||
|
storeIndex = storeIndex + 1; |
||||||
|
} |
||||||
|
} |
||||||
|
Swap(array, right, storeIndex); |
||||||
|
return storeIndex; |
||||||
|
} |
||||||
|
|
||||||
|
static void Swap(int[] array, int index1, int index2) |
||||||
|
{ |
||||||
|
int tmp = array[index1]; |
||||||
|
array[index1] = array[index2]; |
||||||
|
array[index2] = tmp; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||||
|
<PropertyGroup> |
||||||
|
<ProjectGuid>{9C2A1C63-38EA-42CA-BDDD-7D80D9592893}</ProjectGuid> |
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||||
|
<OutputType>Exe</OutputType> |
||||||
|
<RootNamespace>QuickSort</RootNamespace> |
||||||
|
<AssemblyName>QuickSort</AssemblyName> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||||
|
<OutputPath>bin\Debug\</OutputPath> |
||||||
|
<DebugSymbols>True</DebugSymbols> |
||||||
|
<DebugType>Full</DebugType> |
||||||
|
<Optimize>False</Optimize> |
||||||
|
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||||
|
</PropertyGroup> |
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||||
|
<OutputPath>bin\Release\</OutputPath> |
||||||
|
<DebugSymbols>False</DebugSymbols> |
||||||
|
<DebugType>None</DebugType> |
||||||
|
<Optimize>True</Optimize> |
||||||
|
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||||
|
<DefineConstants>TRACE</DefineConstants> |
||||||
|
</PropertyGroup> |
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||||
|
<ItemGroup> |
||||||
|
<Reference Include="System" /> |
||||||
|
<Reference Include="System.Data" /> |
||||||
|
<Reference Include="System.Xml" /> |
||||||
|
</ItemGroup> |
||||||
|
<ItemGroup> |
||||||
|
<Compile Include="AssemblyInfo.cs" /> |
||||||
|
<Compile Include="Program.cs" /> |
||||||
|
</ItemGroup> |
||||||
|
</Project> |
@ -0,0 +1,18 @@ |
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 9.00 |
||||||
|
# Visual Studio 2005 |
||||||
|
# SharpDevelop 3.0.0.2707 |
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickSort", "QuickSort.csproj", "{9C2A1C63-38EA-42CA-BDDD-7D80D9592893}" |
||||||
|
EndProject |
||||||
|
Global |
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||||
|
Debug|Any CPU = Debug|Any CPU |
||||||
|
Release|Any CPU = Release|Any CPU |
||||||
|
EndGlobalSection |
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||||
|
{9C2A1C63-38EA-42CA-BDDD-7D80D9592893}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||||
|
{9C2A1C63-38EA-42CA-BDDD-7D80D9592893}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||||
|
{9C2A1C63-38EA-42CA-BDDD-7D80D9592893}.Release|Any CPU.Build.0 = Release|Any CPU |
||||||
|
{9C2A1C63-38EA-42CA-BDDD-7D80D9592893}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||||
|
EndGlobalSection |
||||||
|
EndGlobal |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue