diff --git a/tests/QuickSort/AssemblyInfo.cs b/tests/QuickSort/AssemblyInfo.cs new file mode 100644 index 000000000..0386c7e48 --- /dev/null +++ b/tests/QuickSort/AssemblyInfo.cs @@ -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.*")] diff --git a/tests/QuickSort/Program.cs b/tests/QuickSort/Program.cs new file mode 100644 index 000000000..4cb22fe3b --- /dev/null +++ b/tests/QuickSort/Program.cs @@ -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; + } +} \ No newline at end of file diff --git a/tests/QuickSort/QuickSort.csproj b/tests/QuickSort/QuickSort.csproj new file mode 100644 index 000000000..191c2a69c --- /dev/null +++ b/tests/QuickSort/QuickSort.csproj @@ -0,0 +1,36 @@ + + + {9C2A1C63-38EA-42CA-BDDD-7D80D9592893} + Debug + AnyCPU + Exe + QuickSort + QuickSort + + + bin\Debug\ + True + Full + False + True + DEBUG;TRACE + + + bin\Release\ + False + None + True + False + TRACE + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/QuickSort/QuickSort.sln b/tests/QuickSort/QuickSort.sln new file mode 100644 index 000000000..8ee47e87f --- /dev/null +++ b/tests/QuickSort/QuickSort.sln @@ -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 diff --git a/tests/QuickSort/bin/Debug/QuickSort.exe b/tests/QuickSort/bin/Debug/QuickSort.exe new file mode 100644 index 000000000..7e3f98ac5 Binary files /dev/null and b/tests/QuickSort/bin/Debug/QuickSort.exe differ diff --git a/tests/QuickSort/bin/Debug/QuickSort.pdb b/tests/QuickSort/bin/Debug/QuickSort.pdb new file mode 100644 index 000000000..0ef5b30bf Binary files /dev/null and b/tests/QuickSort/bin/Debug/QuickSort.pdb differ diff --git a/tests/QuickSort/bin/Release/QuickSort.exe b/tests/QuickSort/bin/Release/QuickSort.exe new file mode 100644 index 000000000..2b829a6ed Binary files /dev/null and b/tests/QuickSort/bin/Release/QuickSort.exe differ