diff --git a/2 Sorting/2.1/2.1.18/Form3.cs b/2 Sorting/2.1/2.1.18/Form3.cs index 824d776e6..95c2ce683 100644 --- a/2 Sorting/2.1/2.1.18/Form3.cs +++ b/2 Sorting/2.1/2.1.18/Form3.cs @@ -10,7 +10,7 @@ public partial class Form3 : Form double[] randomDoubles; int sortI; int sortJ; - int n = 0; + public Form3(int N) { InitializeComponent(); diff --git a/2 Sorting/2.2/2.2.26/AuxInMergeMergeSort.cs b/2 Sorting/2.2/2.2.26/AuxInMergeMergeSort.cs index 73348de70..9a3d0889c 100644 --- a/2 Sorting/2.2/2.2.26/AuxInMergeMergeSort.cs +++ b/2 Sorting/2.2/2.2.26/AuxInMergeMergeSort.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Diagnostics; using Merge; namespace _2._2._26 diff --git a/2 Sorting/2.2/2.2.26/AuxInSortMergeSort.cs b/2 Sorting/2.2/2.2.26/AuxInSortMergeSort.cs index 09cd428ad..0753fcae1 100644 --- a/2 Sorting/2.2/2.2.26/AuxInSortMergeSort.cs +++ b/2 Sorting/2.2/2.2.26/AuxInSortMergeSort.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Diagnostics; using Merge; namespace _2._2._26 diff --git a/2 Sorting/2.3/2.3.1/2.3.1.csproj b/2 Sorting/2.3/2.3.1/2.3.1.csproj new file mode 100644 index 000000000..b66e02169 --- /dev/null +++ b/2 Sorting/2.3/2.3.1/2.3.1.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01} + Exe + _2._3._1 + 2.3.1 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.1/App.config b/2 Sorting/2.3/2.3.1/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.1/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.1/Program.cs b/2 Sorting/2.3/2.3.1/Program.cs new file mode 100644 index 000000000..e7486c1c1 --- /dev/null +++ b/2 Sorting/2.3/2.3.1/Program.cs @@ -0,0 +1,24 @@ +namespace _2._3._1 +{ + /* + * 2.3.1 + * + * 按照 Partition() 方法的轨迹的格式给出该方法是如何切分数组 + * E A S Y Q U E S T I O N 的。 + * + */ + class Program + { + static void Main(string[] args) + { + // a[] + // i j 0 1 2 3 4 5 6 7 8 9 10 11 + // 0 16 E A S Y Q U E S T I O N + // 1 6 E A S Y Q U E S T I O N + // 1 6 E A E Y Q U S S T I O N + // 3 2 E A E Y Q U S S T I O N + // 3 2 E A E Y Q U S S T I O N + // 2 E A E Y Q U S S T I O N + } + } +} diff --git a/2 Sorting/2.3/2.3.1/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.1/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..de16d92f9 --- /dev/null +++ b/2 Sorting/2.3/2.3.1/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.1")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("0b42b539-f300-4d97-b4d0-47249ccc6f01")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.10/2.3.10.csproj b/2 Sorting/2.3/2.3.10/2.3.10.csproj new file mode 100644 index 000000000..cae859cbb --- /dev/null +++ b/2 Sorting/2.3/2.3.10/2.3.10.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {A084203F-4C71-4A74-9D8B-F76EFD052845} + Exe + _2._3._10 + 2.3.10 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.10/App.config b/2 Sorting/2.3/2.3.10/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.10/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.10/Program.cs b/2 Sorting/2.3/2.3.10/Program.cs new file mode 100644 index 000000000..55bb1ad6a --- /dev/null +++ b/2 Sorting/2.3/2.3.10/Program.cs @@ -0,0 +1,34 @@ +using System; + +namespace _2._3._10 +{ + /* + * 2.3.10 + * + * Chebyshev 不等式表明, + * 一个随机变量的标准差距离均值大于 k 的概率小于 1/k^2 。 + * 对于 N=100 万, + * 用 Chebyshev 不等式计算快速排序所使用的比较次数大于 1000 亿次的概率(0.1N^2)。 + * + */ + class Program + { + static void Main(string[] args) + { + // 切比雪夫不等式(Chebyshev's inequality) + // P(|X-μ| ≥ kσ) ≤ 1/(k^2) + // 其中 μ 是期望,σ 是标准差。 + // 在快速排序的比较次数中,μ=2NlnN,σ=0.65N + // (这两个结论可以见 2.3 节的命题 K 和命题 L) + // 题目中要求比较次数大于 0.1N^2,可以得到等式: + // 0.65N * k = 0.1N^2 + // k = 2/13 * N + // 将 N = 1 000 000 代入 + // P(|X-27 631 021| ≥ 100 000 000 000) ≤ 0.00000000004225 + // P ≤ 0.000000004225 % + double N = 10000000; + double k = 0.1 * N / 0.65; + Console.WriteLine(1.0 / (k * k));//4.225x10^-13 + } + } +} diff --git a/2 Sorting/2.3/2.3.10/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.10/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..9b090dfd5 --- /dev/null +++ b/2 Sorting/2.3/2.3.10/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.10")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.10")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("a084203f-4c71-4a74-9d8b-f76efd052845")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.11/2.3.11.csproj b/2 Sorting/2.3/2.3.11/2.3.11.csproj new file mode 100644 index 000000000..a94a68153 --- /dev/null +++ b/2 Sorting/2.3/2.3.11/2.3.11.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {14D53C1D-F1DF-4826-9063-A087C55B289B} + Exe + _2._3._11 + 2.3.11 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.11/App.config b/2 Sorting/2.3/2.3.11/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.11/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.11/Program.cs b/2 Sorting/2.3/2.3.11/Program.cs new file mode 100644 index 000000000..03366cdd2 --- /dev/null +++ b/2 Sorting/2.3/2.3.11/Program.cs @@ -0,0 +1,26 @@ +namespace _2._3._11 +{ + /* + * 2.3.11 + * + * 假如在遇到和切分元素重复的元素时我们继续扫描数组而不是停下来, + * 证明使用这种方法的快速排序在处理只有若干种元素值的数组时运行时间是平方级别的。 + * + */ + class Program + { + static void Main(string[] args) + { + // 只有若干种元素值意味着大量的连续重复。 + //(由于存在打乱这一步骤,不存在连续重复的可能性是很低的) + // 接下来我们考虑这样的连续重复在修改后的快排下的性能。 + // 1 1 1 1 1 1 1 + // 对于这样的数组,枢轴选为 1,j 将会在 j = lo 处终止。 + // 因此最后的结果将是每次只有数组的第一个元素被排序 + // 已知每次切分都是 O(k - 1) 的(i 和 j 都将走完整个子数组) + // 因此这样的快速排序所需时间 = 2*(N-1 + N-2 + ... + 1) = (N-1)N + // 因此对于值相同的子数组,这样的快排运行时间是平方级别的 + // 那么当数组中这样的连续重复内容越多,运行时间就越接近平方级别。 + } + } +} diff --git a/2 Sorting/2.3/2.3.11/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.11/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..4292400ff --- /dev/null +++ b/2 Sorting/2.3/2.3.11/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.11")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.11")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("14d53c1d-f1df-4826-9063-a087c55b289b")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.12/2.3.12.csproj b/2 Sorting/2.3/2.3.12/2.3.12.csproj new file mode 100644 index 000000000..5fca9b9cc --- /dev/null +++ b/2 Sorting/2.3/2.3.12/2.3.12.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3} + Exe + _2._3._12 + 2.3.12 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.12/App.config b/2 Sorting/2.3/2.3.12/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.12/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.12/Program.cs b/2 Sorting/2.3/2.3.12/Program.cs new file mode 100644 index 000000000..47a3762ac --- /dev/null +++ b/2 Sorting/2.3/2.3.12/Program.cs @@ -0,0 +1,37 @@ +namespace _2._3._12 +{ + /* + * 2.3.12 + * + * 按照代码所示轨迹的格式给出信息量最佳的快速排序第一次是如何切分数组 + * B A B A B A B A C A D A B R A 的。 + * + */ + class Program + { + static void Main(string[] args) + { + // a[] + // lt i gt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 + // B A B A B A B A B A C A D A B R A + // 0 1 16 B A B A B A B A B A C A D A B R A + // 1 2 16 A B B A B A B A B A C A D A B R A + // 1 3 16 A B B A B A B A B A C A D A B R A + // 2 4 16 A A B B B A B A B A C A D A B R A + // 2 5 16 A A B B B A B A B A C A D A B R A + // 3 6 16 A A A B B B B A B A C A D A B R A + // 3 7 16 A A A B B B B A B A C A D A B R A + // 4 8 16 A A A A B B B B B A C A D A B R A + // 4 9 16 A A A A B B B B B A C A D A B R A + // 5 10 16 A A A A A B B B B B C A D A B R A + // 5 10 15 A A A A A B B B B B A A D A B R C + // 6 11 15 A A A A A A B B B B B A D A B R C + // 7 12 15 A A A A A A A B B B B B D A B R C + // 7 12 14 A A A A A A A B B B B B R A B D C + // 7 12 13 A A A A A A A B B B B B B A R D C + // 7 13 13 A A A A A A A B B B B B B A R D C + // 8 14 13 A A A A A A A A B B B B B B R D C + // 8 13 A A A A A A A A B B B B B B R D C + } + } +} diff --git a/2 Sorting/2.3/2.3.12/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.12/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..d23cb9150 --- /dev/null +++ b/2 Sorting/2.3/2.3.12/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.12")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.12")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("4b4d4355-6f8f-436b-a471-d33eaa7da7a3")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.13/2.3.13.csproj b/2 Sorting/2.3/2.3.13/2.3.13.csproj new file mode 100644 index 000000000..30867745a --- /dev/null +++ b/2 Sorting/2.3/2.3.13/2.3.13.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {EE14928B-180C-41DE-B6DE-F645F919C152} + Exe + _2._3._13 + 2.3.13 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.13/App.config b/2 Sorting/2.3/2.3.13/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.13/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.13/Program.cs b/2 Sorting/2.3/2.3.13/Program.cs new file mode 100644 index 000000000..9d90105b9 --- /dev/null +++ b/2 Sorting/2.3/2.3.13/Program.cs @@ -0,0 +1,22 @@ +namespace _2._3._13 +{ + /* + * 2.3.13 + * + * 在最佳、平均和最坏情况下,快速排序的递归深度分别是多少? + * 这决定了系统为了追踪递归调用所需的栈的大小。 + * 在最坏情况下保证递归深度为数组大小的对数级的方法请见练习 2.3.20。 + * + */ + class Program + { + static void Main(string[] args) + { + // 最坏情况,每次都只能排除枢轴,总共需要切分 N-1 次,因此总深度为 N-1 + // 最好情况,每次都正好二分,因此总深度为 logN + // 平均情况,将其视为用 N 个元素随机构造一棵 BST, + // 这样的 BST 平均深度为 O(logN) 级(注意不是等于 logN), + // 这个结论可以参见《算法导论》定理 12.4 + } + } +} diff --git a/2 Sorting/2.3/2.3.13/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.13/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..76788da75 --- /dev/null +++ b/2 Sorting/2.3/2.3.13/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.13")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.13")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ee14928b-180c-41de-b6de-f645f919c152")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.14/2.3.14.csproj b/2 Sorting/2.3/2.3.14/2.3.14.csproj new file mode 100644 index 000000000..f254efbb2 --- /dev/null +++ b/2 Sorting/2.3/2.3.14/2.3.14.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {8C16556D-9644-47C3-B88F-648C53FF0701} + Exe + _2._3._14 + 2.3.14 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.14/App.config b/2 Sorting/2.3/2.3.14/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.14/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.14/Program.cs b/2 Sorting/2.3/2.3.14/Program.cs new file mode 100644 index 000000000..8cd456456 --- /dev/null +++ b/2 Sorting/2.3/2.3.14/Program.cs @@ -0,0 +1,37 @@ +namespace _2._3._14 +{ + /* + * 2.3.14 + * + * 证明在用快速排序处理大小为 N 的不重复数组时, + * 比较第 i 大和第 j 大元素的概率为 2/(j - i + 1),并用该结论证明命题 K。 + * + */ + class Program + { + static void Main(string[] args) + { + // 假设 i < j + // 首先,在快速排序中两个元素要发生比较,意味着其中一个被选为了枢轴。 + // 因此如果数组的元素各不相同,那么两个特定元素的比较最多只能发生一次。 + // 考虑一个极限情况,i = 1,j = n + // 也就是说是最大值和最小值比较的概率。 + // 那么一旦枢轴是这两者之外的元素, + // 最大值和最小值会被分在两个不同的子数组中, + // 永远也不可能发生比较了。 + // 因此,在这种特例中, + // 发生比较的概率 = 枢轴是最大值或者最小值的概率 = 2/n = 2/(j-i+1) + // 接下来进行扩展,只要枢轴不选为比 i 小或者比 j 大的元素。 + // 那么第 i 大和第 j 大的元素就会被分到同一个子数组中,重复上述过程 + // 因此概率只跟 i 和 j 之间的元素有关,概率为 2/(j-i+1) + // + // 现在我们已经得到了某两个元素比较的概率 Xij, + // 接下来我们求每两个元素之间比较的概率 X。 + // 令 i 从 1 到 n,j 从 i+1 到 n。 + // E(X) = Σ( Σ( E( Xij ) ) ) + // E(X) = 2(1/2 + 1/3 + 1/4 + ... + 1/(n-i+1)) + // 根据调和级数的性质 + // E(X) ≤ 2nln(n) + } + } +} diff --git a/2 Sorting/2.3/2.3.14/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.14/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..e48e566e2 --- /dev/null +++ b/2 Sorting/2.3/2.3.14/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.14")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.14")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("8c16556d-9644-47c3-b88f-648c53ff0701")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.15/2.3.15.csproj b/2 Sorting/2.3/2.3.15/2.3.15.csproj new file mode 100644 index 000000000..929fc3246 --- /dev/null +++ b/2 Sorting/2.3/2.3.15/2.3.15.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6} + Exe + _2._3._15 + 2.3.15 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.15/App.config b/2 Sorting/2.3/2.3.15/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.15/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.15/BoltsAndNuts.cs b/2 Sorting/2.3/2.3.15/BoltsAndNuts.cs new file mode 100644 index 000000000..3f4bfd78c --- /dev/null +++ b/2 Sorting/2.3/2.3.15/BoltsAndNuts.cs @@ -0,0 +1,194 @@ +using System; + +namespace _2._3._15 +{ + /// + /// 螺母类。 + /// + public class Nut : IComparable> where T : IComparable + { + /// + /// 螺母的值。 + /// + public T Value { get; set; } + + /// + /// 螺母的构造函数。 + /// + /// 螺母的值。 + public Nut(T value) => this.Value = value; + + /// + /// 比较方法,螺母只能和螺丝比较。 + /// + /// 需要比较的螺丝。 + /// + public int CompareTo(Bolt other) + { + return this.Value.CompareTo(other.Value); + } + } + + /// + /// 螺丝类。 + /// + public class Bolt : IComparable> where T : IComparable + { + /// + /// 螺丝的值。 + /// + public T Value { get; set; } + + /// + /// 螺丝的默认构造函数。 + /// + /// 螺丝的值。 + public Bolt(T value) => this.Value = value; + + /// + /// 比较方法,螺丝只能和螺母比较。 + /// + /// 需要比较的螺母。 + /// + public int CompareTo(Nut other) + { + return this.Value.CompareTo(other.Value); + } + } + + /// + /// 用快排的方式解决螺母和螺帽的问题。 + /// + public class BoltsAndNuts + { + private readonly Random random = new Random(); + + /// + /// 默认构造函数。 + /// + public BoltsAndNuts() { } + + /// + /// 对螺丝和螺母排序。 + /// + /// 需要排序的元素类型。 + /// 螺母数组。 + /// 螺丝数组。 + public void Sort(Bolt[] bolts, Nut[] nuts) where T : IComparable + { + if (bolts.Length != nuts.Length) + throw new ArgumentException("数组长度必须一致"); + + Shuffle(bolts); + Shuffle(nuts); + Sort(bolts, nuts, 0, bolts.Length - 1); + } + + /// + /// 对螺丝和螺母排序。 + /// + /// 需要排序的元素类型。 + /// 螺母数组。 + /// 螺丝数组。 + /// 起始下标。 + /// 终止下标。 + public void Sort(Bolt[] bolts, Nut[] nuts, int lo, int hi) where T : IComparable + { + if (hi <= lo) + return; + int j = Partition(bolts, nuts, lo, hi); + Sort(bolts, nuts, lo, j - 1); + Sort(bolts, nuts, j + 1, hi); + } + + /// + /// 对数组进行切分。 + /// + /// 需要排序的数组类型。 + /// 螺母数组。 + /// 螺丝数组。 + /// 起始下标。 + /// 终止下标。 + /// 切分位置。 + private int Partition(Bolt[] bolts, Nut[] nuts, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + Bolt pivotB = bolts[lo]; + // 找到对应螺丝 + for (int k = lo; k <= hi; k++) + { + if (nuts[k].CompareTo(pivotB) == 0) + { + Exch(nuts, k, lo); + break; + } + } + // 先用螺母去套螺丝 + while (true) + { + while (nuts[++i].CompareTo(pivotB) < 0) + if (i == hi) + break; + while (pivotB.CompareTo(nuts[--j]) < 0) + if (j == lo) + break; + + if (i >= j) + break; + Exch(nuts, i, j); + } + Exch(nuts, lo, j); + + // 再用螺丝去比较螺母 + Nut pivotN = nuts[j]; + i = lo; + j = hi + 1; + while (true) + { + while (bolts[++i].CompareTo(pivotN) < 0) + if (i == hi) + break; + while (pivotN.CompareTo(bolts[--j]) < 0) + if (j == lo) + break; + + if (i >= j) + break; + + Exch(bolts, i, j); + } + Exch(bolts, lo, j); + + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + for (int i = 0; i < a.Length; i++) + { + int r = i + this.random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + + /// + /// 交换两个元素。 + /// + /// 元素类型。 + /// 需要交换的第一个元素。 + /// 需要交换的第二个元素。 + private void Exch(T[] a, int lo, int hi) + { + T t = a[lo]; + a[lo] = a[hi]; + a[hi] = t; + } + } +} diff --git a/2 Sorting/2.3/2.3.15/Program.cs b/2 Sorting/2.3/2.3.15/Program.cs new file mode 100644 index 000000000..d98aaa335 --- /dev/null +++ b/2 Sorting/2.3/2.3.15/Program.cs @@ -0,0 +1,42 @@ +using System; + +namespace _2._3._15 +{ + /* + * 2.3.15 + * + * 螺丝和螺帽。(G.J.E.Rawlins)假设有 N 个螺丝和 N 个螺帽混在一堆, + * 你需要快速将它们配对。一个螺丝只会匹配一个螺帽,一个螺帽也只会匹配一个螺丝。 + * 你可以试着把一个螺丝和一个螺帽拧在一起看看谁大了, + * 但不能直接比较两个螺丝或者两个螺帽。 + * 给出一个解决这个问题的有效方法。 + * + */ + class Program + { + static void Main(string[] args) + { + // 思路:先随机拿起一个螺丝(枢轴),与所有的螺母比较,找到合适的那一个 + // 再用找到的螺母与其他螺丝比较,将他们分为较大和较小两部分。 + Bolt[] bolts = new Bolt[10]; + Nut[] nuts = new Nut[10]; + for (int i = 0; i < 10; i++) + { + bolts[i] = new Bolt(i); + nuts[i] = new Nut(i); + } + BoltsAndNuts sort = new BoltsAndNuts(); + sort.Sort(bolts, nuts); + for (int i = 0; i < 10; i++) + { + Console.Write(bolts[i].Value + " "); + } + Console.WriteLine(); + for (int i = 0; i < 10; i++) + { + Console.Write(nuts[i].Value + " "); + } + Console.WriteLine(); + } + } +} diff --git a/2 Sorting/2.3/2.3.15/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.15/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..28dfaf144 --- /dev/null +++ b/2 Sorting/2.3/2.3.15/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.15")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.15")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("277bf76b-d2b5-46a2-9623-baa6ac38a4e6")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.16/2.3.16.csproj b/2 Sorting/2.3/2.3.16/2.3.16.csproj new file mode 100644 index 000000000..24fa0ab2e --- /dev/null +++ b/2 Sorting/2.3/2.3.16/2.3.16.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883} + Exe + _2._3._16 + 2.3.16 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.16/App.config b/2 Sorting/2.3/2.3.16/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.16/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.16/Program.cs b/2 Sorting/2.3/2.3.16/Program.cs new file mode 100644 index 000000000..3b0030a4c --- /dev/null +++ b/2 Sorting/2.3/2.3.16/Program.cs @@ -0,0 +1,40 @@ +using System; +using Quick; + +namespace _2._3._16 +{ + /* + * 2.3.16 + * + * 最佳情况。 + * 编写一段程序来生成使算法 2.5 中的 sort() 方法表现最佳的数组(无重复元素): + * 数组大小为 N 且不包含重复元素, + * 每次切分后两个子数组的大小最多差 1 + * (子数组的大小与含有 N 个相同元素的数组的切分情况相同)。 + * (对于这道练习,我们不需要在排序开始时打乱数组。) + * + */ + class Program + { + static void Main(string[] args) + { + QuickSortAnalyze quick = new QuickSortAnalyze + { + NeedShuffle = false, // 关闭打乱 + NeedPath = true // 显示排序轨迹 + }; + int[] a = QuickBest.Best(10); + for (int i = 0; i < 10; i++) + { + Console.Write(a[i] + " "); + } + Console.WriteLine(); + quick.Sort(a); + for (int i = 0; i < 10; i++) + { + Console.Write(a[i] + " "); + } + Console.WriteLine(); + } + } +} diff --git a/2 Sorting/2.3/2.3.16/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.16/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..d2664e121 --- /dev/null +++ b/2 Sorting/2.3/2.3.16/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.16")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.16")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("691244c9-0de3-4db8-b11e-bca70985c883")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.17/2.3.17.csproj b/2 Sorting/2.3/2.3.17/2.3.17.csproj new file mode 100644 index 000000000..c6df46eaa --- /dev/null +++ b/2 Sorting/2.3/2.3.17/2.3.17.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B} + Exe + _2._3._17 + 2.3.17 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.17/App.config b/2 Sorting/2.3/2.3.17/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.17/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.17/Program.cs b/2 Sorting/2.3/2.3.17/Program.cs new file mode 100644 index 000000000..1e80afee2 --- /dev/null +++ b/2 Sorting/2.3/2.3.17/Program.cs @@ -0,0 +1,37 @@ +using System; +using Quick; + +namespace _2._3._17 +{ + /* + * 2.3.17 + * + * 哨兵。 + * 修改算法 2.5,去掉内循环 while 中的边界检查。 + * 由于切分元素本身就是一个哨兵(v 不可能小于 a[lo]), + * 左侧边界检查是多余的。 + * 要去掉另一个检查,可以在打乱数组后将数组的最大元素方法 a[length - 1] 中。 + * 该元素永远不会移动(除非和相等的元素交换), + * 可以在所有包含它的子数组中成为哨兵。 + * 注意:在处理内部子数组时, + * 右子数组中最左侧的元素可以作为左子数组右边界的哨兵。 + * + */ + class Program + { + static void Main(string[] args) + { + QuickSort quick = new QuickSort(); + QuickSortX quickSortX = new QuickSortX(); + int arrayLength = 1000000; + int[] a = SortCompare.GetRandomArrayInt(arrayLength); + int[] b = new int[arrayLength]; + a.CopyTo(b, 0); + + double time1 = SortCompare.Time(quick, a); + double time2 = SortCompare.Time(quickSortX, b); + Console.WriteLine("QSort\tQSort with Sentinels\t"); + Console.WriteLine(time1 + "\t" + time2 + "\t"); + } + } +} diff --git a/2 Sorting/2.3/2.3.17/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.17/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..5bfe712d6 --- /dev/null +++ b/2 Sorting/2.3/2.3.17/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.17")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.17")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("a5baaa13-8458-43f8-b7a3-7e37f074832b")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.17/QuickSortX.cs b/2 Sorting/2.3/2.3.17/QuickSortX.cs new file mode 100644 index 000000000..58b126659 --- /dev/null +++ b/2 Sorting/2.3/2.3.17/QuickSortX.cs @@ -0,0 +1,100 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._17 +{ + /// + /// 快速排序类。 + /// + public class QuickSortX : BaseSort + { + /// + /// 默认构造函数。 + /// + public QuickSortX() { } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + + // 把最大元素放到最后一位 + int maxIndex = 0; + for (int i = 0; i < a.Length; i++) + { + if (Less(a[maxIndex], a[i])) + maxIndex = i; + } + Exch(a, maxIndex, a.Length - 1); + + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + private void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) ; + // if (i == hi) + // break; + while (Less(v, a[--j])) ; + // if (j == lo) + // break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.18/2.3.18.csproj b/2 Sorting/2.3/2.3.18/2.3.18.csproj new file mode 100644 index 000000000..b530c5288 --- /dev/null +++ b/2 Sorting/2.3/2.3.18/2.3.18.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864} + Exe + _2._3._18 + 2.3.18 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.18/App.config b/2 Sorting/2.3/2.3.18/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.18/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.18/Program.cs b/2 Sorting/2.3/2.3.18/Program.cs new file mode 100644 index 000000000..061c84fe6 --- /dev/null +++ b/2 Sorting/2.3/2.3.18/Program.cs @@ -0,0 +1,45 @@ +using System; +using Quick; + +namespace _2._3._18 +{ + /* + * 2.3.18 + * + * 三取样切分。 + * 为快速排序实现正文所述的三取样切分(参见 2.3.3.2 节)。 + * 运行双倍测试来确认这项改动的效果。 + * + */ + class Program + { + static void Main(string[] args) + { + QuickSort quickNormal = new QuickSort(); + QuickSortMedian3 quickMedian = new QuickSortMedian3(); + int arraySize = 200000; // 初始数组大小。 + const int trialTimes = 4; // 每次实验的重复次数。 + const int trialLevel = 5; // 双倍递增的次数。 + + Console.WriteLine("n\tmedian\tnormal\tratio"); + for (int i = 0; i < trialLevel; i++) + { + double timeMedian = 0; + double timeNormal = 0; + for (int j = 0; j < trialTimes; j++) + { + int[] a = SortCompare.GetRandomArrayInt(arraySize); + int[] b = new int[a.Length]; + a.CopyTo(b, 0); + timeNormal += SortCompare.Time(quickNormal, b); + timeMedian += SortCompare.Time(quickMedian, a); + + } + timeMedian /= trialTimes; + timeNormal /= trialTimes; + Console.WriteLine(arraySize + "\t" + timeMedian + "\t" + timeNormal + "\t" + timeMedian / timeNormal); + arraySize *= 2; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.18/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.18/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..c4127eda6 --- /dev/null +++ b/2 Sorting/2.3/2.3.18/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.18")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.18")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("07ef51f5-aa4c-42c2-91f2-fd8985cca864")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.18/QuickSortMedian3.cs b/2 Sorting/2.3/2.3.18/QuickSortMedian3.cs new file mode 100644 index 000000000..5bea98abc --- /dev/null +++ b/2 Sorting/2.3/2.3.18/QuickSortMedian3.cs @@ -0,0 +1,107 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._18 +{ + /// + /// 三取样快速排序 + /// + public class QuickSortMedian3 : BaseSort + { + /// + /// 默认构造函数。 + /// + public QuickSortMedian3() {} + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + private void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + + // 只有两个元素的数组直接排序 + if (hi == lo + 1) + { + if (Less(a[hi], a[lo])) + Exch(a, lo, hi); + + return; + } + + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + + if (Less(a[lo + 1], a[lo])) + Exch(a, lo + 1, lo); + if (Less(a[lo + 2], a[lo])) + Exch(a, lo + 2, lo); + if (Less(a[lo + 2], a[lo + 1])) + Exch(a, lo + 1, lo + 2); + + Exch(a, lo, lo + 1); // 中位数放最左侧 + Exch(a, hi, lo + 2); // 较大的值放最右侧作为哨兵 + + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) ; + while (Less(v, a[--j])) ; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.19/2.3.19.csproj b/2 Sorting/2.3/2.3.19/2.3.19.csproj new file mode 100644 index 000000000..3adb3c3f9 --- /dev/null +++ b/2 Sorting/2.3/2.3.19/2.3.19.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72} + Exe + _2._3._19 + 2.3.19 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.19/App.config b/2 Sorting/2.3/2.3.19/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.19/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.19/Program.cs b/2 Sorting/2.3/2.3.19/Program.cs new file mode 100644 index 000000000..6be37e2f3 --- /dev/null +++ b/2 Sorting/2.3/2.3.19/Program.cs @@ -0,0 +1,53 @@ +using System; +using Quick; + +namespace _2._3._19 +{ + /* + * 2.3.19 + * + * 五取样切分。 + * 实现一种基于随机抽取子数组中 5 个元素并取中位数进行切分的快速排序。 + * 将取样元素放在数组的一侧以保证只有中位数元素参与了切分。 + * 运行双倍测试来确定这项改动的效果, + * 并和标准的快速排序以及三取样的快速排序(请见上一道练习)进行比较。 + * 附加题:找到一种对于任意输入都只需要少于 7 次比较的五取样算法。 + * + */ + class Program + { + static void Main(string[] args) + { + QuickSort quickNormal = new QuickSort(); + QuickSortMedian3 quickMedian3 = new QuickSortMedian3(); + QuickSortMedian5 quickMedian5 = new QuickSortMedian5(); + int arraySize = 200000; // 初始数组大小。 + const int trialTimes = 4; // 每次实验的重复次数。 + const int trialLevel = 6; // 双倍递增的次数。 + + Console.WriteLine("n\tmedian5\tmedian3\tnormal\tmedian5/normal\t\tmedian5/median3"); + for (int i = 0; i < trialLevel; i++) + { + double timeMedian3 = 0; + double timeMedian5 = 0; + double timeNormal = 0; + for (int j = 0; j < trialTimes; j++) + { + int[] a = SortCompare.GetRandomArrayInt(arraySize); + int[] b = new int[a.Length]; + int[] c = new int[a.Length]; + a.CopyTo(b, 0); + a.CopyTo(c, 0); + timeNormal += SortCompare.Time(quickNormal, a); + timeMedian3 += SortCompare.Time(quickMedian3, b); + timeMedian5 += SortCompare.Time(quickMedian5, c); + } + timeMedian5 /= trialTimes; + timeMedian3 /= trialTimes; + timeNormal /= trialTimes; + Console.WriteLine(arraySize + "\t" + timeMedian5 + "\t" + timeMedian3 + "\t" + timeNormal + "\t" + timeMedian5 / timeNormal + "\t" + timeMedian5/timeMedian3); + arraySize *= 2; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.19/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.19/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1bb447c53 --- /dev/null +++ b/2 Sorting/2.3/2.3.19/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.19")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.19")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("c2ffad8e-da39-4f50-883f-c72febecdf72")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.19/QuickSortMedian3.cs b/2 Sorting/2.3/2.3.19/QuickSortMedian3.cs new file mode 100644 index 000000000..36f122e67 --- /dev/null +++ b/2 Sorting/2.3/2.3.19/QuickSortMedian3.cs @@ -0,0 +1,113 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._19 +{ + /// + /// 三取样快速排序 + /// + public class QuickSortMedian3 : BaseSort + { + /// + /// 默认构造函数。 + /// + public QuickSortMedian3() {} + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + private void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + + // 少于五个元素的数组直接进行插入排序 + if (hi - lo + 1 < 5) + { + int n = hi - lo + 1; + for (int i = lo; i - lo < n; i++) + { + for (int k = i; k > 0 && Less(a[k], a[k - 1]); --k) + { + Exch(a, k, k - 1); + } + } + + return; + } + + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + + if (Less(a[lo + 1], a[lo])) + Exch(a, lo + 1, lo); + if (Less(a[lo + 2], a[lo])) + Exch(a, lo + 2, lo); + if (Less(a[lo + 2], a[lo + 1])) + Exch(a, lo + 1, lo + 2); + + Exch(a, lo, lo + 1); // 中位数放最左侧 + Exch(a, hi, lo + 2); // 较大的值放最右侧作为哨兵 + + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) ; + while (Less(v, a[--j])) ; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.19/QuickSortMedian5.cs b/2 Sorting/2.3/2.3.19/QuickSortMedian5.cs new file mode 100644 index 000000000..f280348d2 --- /dev/null +++ b/2 Sorting/2.3/2.3.19/QuickSortMedian5.cs @@ -0,0 +1,151 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._19 +{ + /// + /// 五取样快速排序 + /// + public class QuickSortMedian5 : BaseSort + { + /// + /// 默认构造函数。 + /// + public QuickSortMedian5() {} + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + private void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + + // 少于五个元素的数组直接进行插入排序 + if (hi - lo + 1 < 5) + { + int n = hi - lo + 1; + for (int i = lo; i - lo < n; i++) + { + for (int k = i; k > 0 && Less(a[k], a[k - 1]); --k) + { + Exch(a, k, k - 1); + } + } + + return; + } + + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + + // 假设为 a b c d e 五个数字 + // 首先对 b c 排序 + if (Less(a[lo + 2], a[lo + 1])) + Exch(a, lo + 2, lo + 1); + // 然后再排序 d e + if (Less(a[lo + 4], a[lo + 3])) + Exch(a, lo + 4, lo + 3); + + // 这时满足 b < c, d < e + // 比较 b d,把较小的一组放到 b c 的位置上去 + if (Less(a[lo + 3], a[lo + 1])) + { + Exch(a, lo + 1, lo + 3); + Exch(a, lo + 2, lo + 4); + } + + // 这时满足 b < c, b < d < e,即 b 是 b c d e 中的最小值 + // 交换 a 和 b + Exch(a, lo, lo + 1); + + // 重新排序 b c + if (Less(a[lo + 2], a[lo + 1])) + Exch(a, lo + 2, lo + 1); + + // 这时再次满足 b < c, d < e + // 比较 b d,把最小的一组放到 b c 的位置上去 + if (Less(a[lo + 3], a[lo + 1])) + { + Exch(a, lo + 1, lo + 3); + Exch(a, lo + 2, lo + 4); + } + + // 这时 a 和 b 为五个数中的最小值和次小值(顺序不固定,a 也可以是次小值) + // 最后比较 c 和 d,较小的那一个即为中位数(即第三小的数) + if (Less(a[lo + 3], a[lo + 2])) + Exch(a, lo + 3, lo + 2); + + // 此时 c 即为中位数 + Exch(a, lo, lo + 2); + + // d e 放到数组末尾充当哨兵 + Exch(a, lo + 3, hi); + Exch(a, lo + 4, hi - 1); + + // 调整指针位置,前两位和后两位都已经在合适位置了 + j -= 2; + i += 2; + + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) ; + while (Less(v, a[--j])) ; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.2/2.3.2.csproj b/2 Sorting/2.3/2.3.2/2.3.2.csproj new file mode 100644 index 000000000..59f0465ee --- /dev/null +++ b/2 Sorting/2.3/2.3.2/2.3.2.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {C713169E-361B-4DF3-BCCA-68740199FF52} + Exe + _2._3._2 + 2.3.2 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.2/App.config b/2 Sorting/2.3/2.3.2/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.2/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.2/Program.cs b/2 Sorting/2.3/2.3.2/Program.cs new file mode 100644 index 000000000..26a211b97 --- /dev/null +++ b/2 Sorting/2.3/2.3.2/Program.cs @@ -0,0 +1,32 @@ +namespace _2._3._2 +{ + /* + * 2.3.2 + * + * 按照本节中快速排序所示轨迹的格式给出快速排序是如何将数组 E A S Y Q U E S T I O N 排序的 + * (出于练习的目的,可以忽略开头打乱数组的部分)。 + * + */ + class Program + { + static void Main(string[] args) + { + // a[] + // lo j hi 0 1 2 3 4 5 6 7 8 9 10 11 + // E A S Y Q U E S T I O N + // 0 2 11 E A E Y Q U S S T I O N + // 0 1 1 A E E Y Q U S S T I O N + // 0 0 A E E Y Q U S S T I O N + // 3 11 11 A E E N Q U S S Y I O Y + // 3 4 10 A E E I N U S S T Q O Y + // 3 3 A E E I N U S S T Q O Y + // 5 10 10 A E E I N O S S T Q U Y + // 5 5 9 A E E I N O S S T Q U Y + // 6 7 9 A E E I N O Q S T S U Y + // 6 6 A E E I N O Q S T S U Y + // 8 9 9 A E E I N O Q S S T U Y + // 8 8 A E E I N O Q S S T U Y + // A E E I N O Q S S T U Y + } + } +} diff --git a/2 Sorting/2.3/2.3.2/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.2/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..53bdc8fa7 --- /dev/null +++ b/2 Sorting/2.3/2.3.2/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.2")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.2")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("c713169e-361b-4df3-bcca-68740199ff52")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.20/2.3.20.csproj b/2 Sorting/2.3/2.3.20/2.3.20.csproj new file mode 100644 index 000000000..627509d42 --- /dev/null +++ b/2 Sorting/2.3/2.3.20/2.3.20.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238} + Exe + _2._3._20 + 2.3.20 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.20/App.config b/2 Sorting/2.3/2.3.20/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.20/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.20/Node.cs b/2 Sorting/2.3/2.3.20/Node.cs new file mode 100644 index 000000000..d5c1e7928 --- /dev/null +++ b/2 Sorting/2.3/2.3.20/Node.cs @@ -0,0 +1,20 @@ +namespace _2._3._20 +{ + /// + /// 链表结点类。 + /// + /// 结点存放的元素类型。 + public class Node + { + public T item; + public Node next; + + public Node() { } + + public Node(Node node) + { + this.item = node.item; + this.next = node.next; + } + } +} diff --git a/2 Sorting/2.3/2.3.20/Program.cs b/2 Sorting/2.3/2.3.20/Program.cs new file mode 100644 index 000000000..6e6ec5636 --- /dev/null +++ b/2 Sorting/2.3/2.3.20/Program.cs @@ -0,0 +1,47 @@ +using System; +using Quick; + +namespace _2._3._20 +{ + /* + * 2.3.20 + * + * 非递归的快速排序。 + * 实现一个非递归的快速排序, + * 使用一个循环来将弹出栈的子数组切分并将结果子数组重新压入栈。 + * 注意: + * 先将较大的子数组压入栈,这样就可以保证栈最多只会有 lgN 个元素。 + * + */ + class Program + { + static void Main(string[] args) + { + QuickSort quickNormal = new QuickSort(); + QuickSortNonRecursive quickNonRecursive = new QuickSortNonRecursive(); + int arraySize = 200000; // 初始数组大小。 + const int trialTimes = 4; // 每次实验的重复次数。 + const int trialLevel = 5; // 双倍递增的次数。 + + Console.WriteLine("n\tnon-recursive\tnormal\tratio"); + for (int i = 0; i < trialLevel; i++) + { + double timeRecursive = 0; + double timeNormal = 0; + for (int j = 0; j < trialTimes; j++) + { + int[] a = SortCompare.GetRandomArrayInt(arraySize); + int[] b = new int[a.Length]; + a.CopyTo(b, 0); + timeNormal += SortCompare.Time(quickNormal, b); + timeRecursive += SortCompare.Time(quickNonRecursive, a); + + } + timeRecursive /= trialTimes; + timeNormal /= trialTimes; + Console.WriteLine(arraySize + "\t" + timeRecursive + "\t\t" + timeNormal + "\t" + timeRecursive / timeNormal); + arraySize *= 2; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.20/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.20/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f71f013bd --- /dev/null +++ b/2 Sorting/2.3/2.3.20/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.20")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.20")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("acb6b05b-f262-4950-a5e1-6eaa48ee8238")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.20/QuickSortNonRecursive.cs b/2 Sorting/2.3/2.3.20/QuickSortNonRecursive.cs new file mode 100644 index 000000000..c0fa389c4 --- /dev/null +++ b/2 Sorting/2.3/2.3.20/QuickSortNonRecursive.cs @@ -0,0 +1,106 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._20 +{ + /// + /// 快速排序类。 + /// + public class QuickSortNonRecursive : BaseSort + { + /// + /// 默认构造函数。 + /// + public QuickSortNonRecursive() { } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Stack stack = new Stack(); + stack.Push(0); + stack.Push(a.Length - 1); + + while (!stack.IsEmpty()) + { + // 压入顺序是先 lo,再 hi,故弹出顺序是先 hi 再 lo + int hi = stack.Pop(); + int lo = stack.Pop(); + + if (hi <= lo) + continue; + + int j = Partition(a, lo, hi); + + // 让较大的子数组先入栈(先排序较小的子数组) + if (j - lo > hi - j) + { + stack.Push(lo); + stack.Push(j - 1); + + stack.Push(j + 1); + stack.Push(hi); + } + else + { + stack.Push(j + 1); + stack.Push(hi); + + stack.Push(lo); + stack.Push(j - 1); + } + } + Debug.Assert(IsSorted(a)); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.20/Stack.cs b/2 Sorting/2.3/2.3.20/Stack.cs new file mode 100644 index 000000000..0a0e9eb75 --- /dev/null +++ b/2 Sorting/2.3/2.3.20/Stack.cs @@ -0,0 +1,196 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace _2._3._20 +{ + /// + /// 栈类。 + /// + /// 栈中存放的元素类型。 + public class Stack : IEnumerable + { + private Node first; + private int count; + + /// + /// 默认构造函数。 + /// + public Stack() + { + this.first = null; + this.count = 0; + } + + /// + /// 复制构造函数。 + /// + /// + public Stack(Stack s) + { + if (s.first != null) + { + this.first = new Node(s.first); + for (Node x = this.first; x.next != null; x = x.next) + { + x.next = new Node(x.next); + } + } + this.count = s.count; + } + + /// + /// 检查栈是否为空。 + /// + /// + public bool IsEmpty() + { + return this.first == null; + } + + /// + /// 返回栈内元素的数量。 + /// + /// + public int Size() + { + return this.count; + } + + /// + /// 将一个元素压入栈中。 + /// + /// 要压入栈中的元素。 + public void Push(Item item) + { + Node oldFirst = this.first; + this.first = new Node(); + this.first.item = item; + this.first.next = oldFirst; + this.count++; + } + + /// + /// 将一个元素从栈中弹出,返回弹出的元素。 + /// + /// + public Item Pop() + { + if (IsEmpty()) + throw new InvalidOperationException("Stack Underflow"); + Item item = this.first.item; + this.first = this.first.next; + this.count--; + return item; + } + + /// + /// 返回栈顶元素(但不弹出它)。 + /// + /// + public Item Peek() + { + if (IsEmpty()) + throw new InvalidOperationException("Stack Underflow"); + return this.first.item; + } + + /// + /// 将两个栈连接。 + /// + /// 第一个栈。 + /// 第二个栈(将被删除)。 + /// + public static Stack Catenation(Stack s1, Stack s2) + { + if (s1.IsEmpty()) + { + s1.first = s2.first; + s1.count = s2.count; + } + else + { + Node last = s1.first; + while (last.next != null) + { + last = last.next; + } + last.next = s2.first; + s1.count += s2.count; + } + s2 = null; + return s1; + } + + /// + /// 创建栈的浅表副本。 + /// + /// + public Stack Copy() + { + Stack temp = new Stack(); + temp.first = this.first; + temp.count = this.count; + return temp; + } + + public override string ToString() + { + StringBuilder s = new StringBuilder(); + foreach (Item n in this) + { + s.Append(n); + s.Append(' '); + } + return s.ToString(); + } + + public IEnumerator GetEnumerator() + { + return new StackEnumerator(this.first); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + private class StackEnumerator : IEnumerator + { + private Node current; + private Node first; + + public StackEnumerator(Node first) + { + this.current = new Node(); + this.current.next = first; + this.first = this.current; + } + + Item IEnumerator.Current => this.current.item; + + object IEnumerator.Current => this.current.item; + + void IDisposable.Dispose() + { + this.current = null; + this.first = null; + } + + bool IEnumerator.MoveNext() + { + if (this.current.next == null) + return false; + + this.current = this.current.next; + return true; + } + + void IEnumerator.Reset() + { + this.current = this.first; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.21/2.3.21.csproj b/2 Sorting/2.3/2.3.21/2.3.21.csproj new file mode 100644 index 000000000..570b35fac --- /dev/null +++ b/2 Sorting/2.3/2.3.21/2.3.21.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {657EF2E4-1D20-475B-8B22-54A917A38210} + Exe + _2._3._21 + 2.3.21 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.21/App.config b/2 Sorting/2.3/2.3.21/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.21/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.21/Program.cs b/2 Sorting/2.3/2.3.21/Program.cs new file mode 100644 index 000000000..99ce0d48d --- /dev/null +++ b/2 Sorting/2.3/2.3.21/Program.cs @@ -0,0 +1,35 @@ +namespace _2._3._21 +{ + /* + * 2.3.21 + * + * 将重复元素排序的比较次数的下界。 + * 完成命题 M 的证明的第一部分。 + * 参考命题 I 的证明并注意当有 k 个主键值时所有元素存在 + * N!/f_1!f_2!...f_k! 种不同的排列, + * 其中第 i 个主键值出现的概率为 f_1(即N_p_i,按照命题 M 的记法), + * 且 f_1+... +f_k=N。 + * + */ + class Program + { + static void Main(string[] args) + { + // f_i 为第 i 种主键出现的频率,必为非负整数 + // 当主键值各不相同时,我们有 + // k = N,f_1=f_2=...=f_k=1 + // 此时可能的排列总数为 N!/f_1!...f_k!=N!/1=N! + // 故最少比较次数即为有 N! 个叶子节点的二叉树的最小高度 + // h>=logN! + // 那么当主键值有重复时,我们同理可以推得 + // h>=log(N!/(f_1!...f_k!)) + // 当主键值有重复时,k < N, + // 那么为使 f_1+...+f_k=N + // 必存在一个 f_m > 1,且其他 f_i >= 1 + // 故此时有 f_1!f_2!...f_k! >= 2 成立 + // 因此 N!/f_1!...f_k! >= N! + // 那么 h >= log(N!/(f_1!...f_k!)) >= log(N!) ~ NlogN + // 证毕 + } + } +} diff --git a/2 Sorting/2.3/2.3.21/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.21/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..3e118e950 --- /dev/null +++ b/2 Sorting/2.3/2.3.21/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.21")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.21")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("657ef2e4-1d20-475b-8b22-54a917a38210")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.22/2.3.22.csproj b/2 Sorting/2.3/2.3.22/2.3.22.csproj new file mode 100644 index 000000000..56a5c092c --- /dev/null +++ b/2 Sorting/2.3/2.3.22/2.3.22.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {C51D70DF-E143-4541-93FA-3291863FA67D} + Exe + _2._3._22 + 2.3.22 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.22/App.config b/2 Sorting/2.3/2.3.22/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.22/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.22/Program.cs b/2 Sorting/2.3/2.3.22/Program.cs new file mode 100644 index 000000000..5427f179c --- /dev/null +++ b/2 Sorting/2.3/2.3.22/Program.cs @@ -0,0 +1,57 @@ +using System; +using Quick; + +namespace _2._3._22 +{ + /* + * 2.3.22 + * + * 快速三向切分。(J.Bently,D.McIlroy) + * 用将重复元素放置于子数组两端的方式实现一个信息量最优的排序算法。 + * 使用两个索引 p 和 q,使得 a[lo...p-1] 和 a[q+1..hi] 的元素都和 a[lo] 相等。 + * 使用另外两个索引 i 和 j, + * 使得 a[p...i-1] 小于 a[lo],a[j+i..q] 大于 a[lo]。 + * 在内循环中加入代码,在 a[i] 和 v 相当时将其与 a[p] 交换(并将 p 加 1), + * 在 a[j] 和 v 相等且 a[i] 和 a[j] 尚未和 v 进行比较之前将其与 a[q] 交换。 + * 添加在切分循环结束后将和 v 相等的元素交换到正确位置的代码,如图 2.3.6 所示。 + * 请注意: + * 这里实现的代码和正文中给出的代码时等价的, + * 因为这里额外的交换用于和切分元素相等的元素, + * 而正文中的代码将额外的交换用于和切分元素不等的元素。 + * + */ + class Program + { + static void Main(string[] args) + { + QuickSort quickNormal = new QuickSort(); + QuickBentleyMcIlroy quickBentleyMcIlroy = new QuickBentleyMcIlroy(); + int arraySize = 800000; // 初始数组大小。 + const int trialTimes = 1; // 每次实验的重复次数。 + const int trialLevel = 8; // 双倍递增的次数。 + + Console.WriteLine("n\t\t3way\tnormal\tratio"); + for (int i = 0; i < trialLevel; i++) + { + double timeBentleyMcIlroy = 0; + double timeNormal = 0; + for (int j = 0; j < trialTimes; j++) + { + int[] a = SortCompare.GetRandomArrayInt(arraySize); + int[] b = new int[a.Length]; + a.CopyTo(b, 0); + timeNormal += SortCompare.Time(quickNormal, b); + timeBentleyMcIlroy += SortCompare.Time(quickBentleyMcIlroy, a); + + } + timeBentleyMcIlroy /= trialTimes; + timeNormal /= trialTimes; + if (arraySize < 10000000) + Console.WriteLine(arraySize + "\t\t" + timeBentleyMcIlroy + "\t" + timeNormal + "\t" + timeBentleyMcIlroy / timeNormal); + else + Console.WriteLine(arraySize + "\t" + timeBentleyMcIlroy + "\t" + timeNormal + "\t" + timeBentleyMcIlroy / timeNormal); + arraySize *= 2; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.22/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.22/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..9042e7e27 --- /dev/null +++ b/2 Sorting/2.3/2.3.22/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.22")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.22")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("c51d70df-e143-4541-93fa-3291863fa67d")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.23/2.3.23.csproj b/2 Sorting/2.3/2.3.23/2.3.23.csproj new file mode 100644 index 000000000..9b8b3ae72 --- /dev/null +++ b/2 Sorting/2.3/2.3.23/2.3.23.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA} + Exe + _2._3._23 + 2.3.23 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.23/App.config b/2 Sorting/2.3/2.3.23/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.23/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.23/Program.cs b/2 Sorting/2.3/2.3.23/Program.cs new file mode 100644 index 000000000..5396af703 --- /dev/null +++ b/2 Sorting/2.3/2.3.23/Program.cs @@ -0,0 +1,51 @@ +using System; +using Quick; + +namespace _2._3._23 +{ + /* + * 2.3.23 + * + * Java 的排序库函数。 + * 在练习 2.3.22 的代码中使用 Tukey's ninther 方法来找出切分元素——选择三组, + * 每组三个元素,分别取三组元素的中位数, + * 然后取三个中位数的中位数作为切分元素, + * 且在排序小数组时切换到插入排序。 + * + */ + class Program + { + static void Main(string[] args) + { + // 这些改动已经在上一题中实现过了,见 2.3.22 + QuickSort quickNormal = new QuickSort(); + QuickBentleyMcIlroy quickBentleyMcIlroy = new QuickBentleyMcIlroy(); + int arraySize = 800000; // 初始数组大小。 + const int trialTimes = 1; // 每次实验的重复次数。 + const int trialLevel = 8; // 双倍递增的次数。 + + Console.WriteLine("n\t\t3way\tnormal\tratio"); + for (int i = 0; i < trialLevel; i++) + { + double timeBentleyMcIlroy = 0; + double timeNormal = 0; + for (int j = 0; j < trialTimes; j++) + { + int[] a = SortCompare.GetRandomArrayInt(arraySize); + int[] b = new int[a.Length]; + a.CopyTo(b, 0); + timeNormal += SortCompare.Time(quickNormal, b); + timeBentleyMcIlroy += SortCompare.Time(quickBentleyMcIlroy, a); + + } + timeBentleyMcIlroy /= trialTimes; + timeNormal /= trialTimes; + if (arraySize < 10000000) + Console.WriteLine(arraySize + "\t\t" + timeBentleyMcIlroy + "\t" + timeNormal + "\t" + timeBentleyMcIlroy / timeNormal); + else + Console.WriteLine(arraySize + "\t" + timeBentleyMcIlroy + "\t" + timeNormal + "\t" + timeBentleyMcIlroy / timeNormal); + arraySize *= 2; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.23/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.23/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..b7db54844 --- /dev/null +++ b/2 Sorting/2.3/2.3.23/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.23")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.23")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("df288ae1-d508-4b83-a31c-f7c15769b7ca")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.24/2.3.24.csproj b/2 Sorting/2.3/2.3.24/2.3.24.csproj new file mode 100644 index 000000000..ba7636367 --- /dev/null +++ b/2 Sorting/2.3/2.3.24/2.3.24.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E} + Exe + _2._3._24 + 2.3.24 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.24/App.config b/2 Sorting/2.3/2.3.24/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.24/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.24/Program.cs b/2 Sorting/2.3/2.3.24/Program.cs new file mode 100644 index 000000000..73c1a03f3 --- /dev/null +++ b/2 Sorting/2.3/2.3.24/Program.cs @@ -0,0 +1,58 @@ +using System; +using Quick; + +namespace _2._3._24 +{ + /* + * 2.3.24 + * + * 取样排序。(W.Frazer,A.McKellar) + * 实现一个快速排序, + * 取样大小为 2^k-1。首先将取样得到的元素排序, + * 然后在递归函数中使用样品的中位数切分。 + * 分为两部分的其余样品元素无需再次排序并可以分别应用于原数组的两个子数组。 + * 这种算法称为取样排序。 + * + */ + class Program + { + static void Main(string[] args) + { + QuickSort quickNormal = new QuickSort(); + SampleSort sampleSort = new SampleSort(); + int arraySize = 1600000; // 初始数组大小。 + const int kSteps = 10; // 取样 k 值的递增次数。 + const int trialTimes = 1; // 每次实验的重复次数。 + const int trialLevel = 2; // 双倍递增的次数。 + + Console.WriteLine("k\tn\t\tsample\tnormal\tratio"); + for (int i = 0; i < kSteps; i++) + { + int array = arraySize; + for (int j = 0; j < trialLevel; j++) + { + double timeSample = 0; + double timeNormal = 0; + for (int k = 0; k < trialTimes; k++) + { + int[] a = SortCompare.GetRandomArrayInt(array); + int[] b = new int[a.Length]; + a.CopyTo(b, 0); + timeNormal += SortCompare.Time(quickNormal, b); + timeSample += SortCompare.Time(sampleSort, a); + + } + timeSample /= trialTimes; + timeNormal /= trialTimes; + if (arraySize < 10000000) + Console.WriteLine(sampleSort.K + "\t" + array + "\t\t" + timeSample + "\t" + timeNormal + "\t" + timeSample / timeNormal); + else + Console.WriteLine(sampleSort.K + "\t" + array + "\t" + timeSample + "\t" + timeNormal + "\t" + timeSample / timeNormal); + array *= 2; + } + sampleSort.K++; + } + + } + } +} diff --git a/2 Sorting/2.3/2.3.24/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.24/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..0c2cf4106 --- /dev/null +++ b/2 Sorting/2.3/2.3.24/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.24")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.24")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("e8871a11-d22e-4d50-be68-470dd4671d8e")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.25/2.3.25.csproj b/2 Sorting/2.3/2.3.25/2.3.25.csproj new file mode 100644 index 000000000..161af6c76 --- /dev/null +++ b/2 Sorting/2.3/2.3.25/2.3.25.csproj @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1} + WinExe + _2._3._25 + 2.3.25 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + Form + + + Form2.cs + + + + + + Form1.cs + + + Form2.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.25/App.config b/2 Sorting/2.3/2.3.25/App.config new file mode 100644 index 000000000..1520030ff --- /dev/null +++ b/2 Sorting/2.3/2.3.25/App.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.25/Form1.Designer.cs b/2 Sorting/2.3/2.3.25/Form1.Designer.cs new file mode 100644 index 000000000..0d448664e --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Form1.Designer.cs @@ -0,0 +1,107 @@ +namespace _2._3._25 +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label1 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + this.SuspendLayout(); + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(114, 12); + this.numericUpDown1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.numericUpDown1.Maximum = new decimal(new int[] { + 1410065408, + 2, + 0, + 0}); + this.numericUpDown1.Minimum = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(177, 35); + this.numericUpDown1.TabIndex = 0; + this.numericUpDown1.Value = new decimal(new int[] { + 1000, + 0, + 0, + 0}); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(10, 14); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(96, 28); + this.label1.TabIndex = 1; + this.label1.Text = "数组大小"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(298, 12); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(139, 34); + this.button1.TabIndex = 2; + this.button1.Text = "开始"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 28F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 59); + this.Controls.Add(this.button1); + this.Controls.Add(this.label1); + this.Controls.Add(this.numericUpDown1); + this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "Form1"; + this.Text = "2.3.25"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button1; + } +} \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.25/Form1.cs b/2 Sorting/2.3/2.3.25/Form1.cs new file mode 100644 index 000000000..7b90de4fa --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Form1.cs @@ -0,0 +1,19 @@ +using System; +using System.Windows.Forms; + +namespace _2._3._25 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + Form2 panel = new Form2((int)this.numericUpDown1.Value); + panel.ShowDialog(); + } + } +} diff --git a/2 Sorting/2.3/2.3.25/Form1.resx b/2 Sorting/2.3/2.3.25/Form1.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.25/Form2.Designer.cs b/2 Sorting/2.3/2.3.25/Form2.Designer.cs new file mode 100644 index 000000000..4ecd4eca9 --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Form2.Designer.cs @@ -0,0 +1,58 @@ +namespace _2._3._25 +{ + partial class Form2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.SuspendLayout(); + // + // backgroundWorker1 + // + this.backgroundWorker1.WorkerReportsProgress = true; + this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); + this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); + this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); + // + // Form2 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(776, 736); + this.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Name = "Form2"; + this.Text = "绘图结果"; + this.Shown += new System.EventHandler(this.Form2_Shown); + this.ResumeLayout(false); + + } + + #endregion + + private System.ComponentModel.BackgroundWorker backgroundWorker1; + } +} \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.25/Form2.cs b/2 Sorting/2.3/2.3.25/Form2.cs new file mode 100644 index 000000000..6b03d3787 --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Form2.cs @@ -0,0 +1,125 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Quick; + +namespace _2._3._25 +{ + public partial class Form2 : Form + { + /// + /// 测试数组大小。 + /// + public int N = 100; + + public Form2(int n) + { + InitializeComponent(); + this.N = n; + } + + /// + /// 启动页面时启动后台测试。 + /// + /// + /// + private void Form2_Shown(object sender, EventArgs e) + { + this.Text = "正在绘图"; + this.backgroundWorker1.RunWorkerAsync(); + } + + /// + /// 后台测试方法。 + /// + /// + /// + private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) + { + BackgroundWorker worker = sender as BackgroundWorker; + QuickSortInsertion quickSortInsertion = new QuickSortInsertion(); + double[] timeRecord = new double[31]; + for (int i = 0; i <= 30; i++) + { + worker.ReportProgress(i * 3); + quickSortInsertion.M = i; + int[] data = SortCompare.GetRandomArrayInt(this.N); + timeRecord[i] = SortCompare.Time(quickSortInsertion, data); + } + e.Result = timeRecord; + } + + /// + /// 更新后台进度方法。 + /// + /// + /// + private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + this.Text = "正在绘图,已完成 " + e.ProgressPercentage + " %"; + } + + /// + /// 测试完毕,进行绘图的方法。 + /// + /// + /// + private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + if (e.Error != null) + { + MessageBox.Show(e.Error.Message); + } + double[] result = e.Result as double[]; + + Graphics graphics = this.CreateGraphics(); + + // 获得绘图区矩形。 + RectangleF rect = this.ClientRectangle; + float unitX = rect.Width / 10; + float unitY = rect.Width / 10; + + // 添加 10% 边距作为文字区域。 + RectangleF center = new RectangleF + (rect.X + unitX, rect.Y + unitY, + rect.Width - 2 * unitX, rect.Height - 2 * unitY); + + // 绘制坐标系。 + graphics.DrawLine(Pens.Black, center.Left, center.Top, center.Left, center.Bottom); + graphics.DrawLine(Pens.Black, center.Left, center.Bottom, center.Right, center.Bottom); + graphics.DrawString(result.Max().ToString(), this.Font, Brushes.Black, rect.Location); + graphics.DrawString(result.Length.ToString(), this.Font, Brushes.Black, center.Right, center.Bottom); + graphics.DrawString("0", this.Font, Brushes.Black, rect.Left, center.Bottom); + + // 初始化点。 + PointF[] bluePoints = new PointF[result.Length]; + unitX = center.Width / result.Length; + unitY = center.Height / (float)result.Max(); + + for (int i = 0; i < result.Length; i++) + { + bluePoints[i] = new PointF(center.Left + unitX * (i + 1), center.Bottom - (float)(result[i] * unitY) - 10); + } + + // 绘制点。 + for (int i = 0; i < result.Length; i++) + { + graphics.FillEllipse(Brushes.Blue, new RectangleF(bluePoints[i], new Size(10, 10))); + } + + graphics.Dispose(); + + this.Text = "绘图结果"; + int min = 0; + for (int i = 0; i < result.Length; i++) + { + if (result[i] < result[min]) + min = i; + } + string report = "M " + min + "\r\ntime " + result[min]; + MessageBox.Show(report, "最优结果"); + } + } +} diff --git a/2 Sorting/2.3/2.3.25/Form2.resx b/2 Sorting/2.3/2.3.25/Form2.resx new file mode 100644 index 000000000..59099f264 --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Form2.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.25/Program.cs b/2 Sorting/2.3/2.3.25/Program.cs new file mode 100644 index 000000000..89d007e2a --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Program.cs @@ -0,0 +1,32 @@ +using System; +using System.Windows.Forms; + +namespace _2._3._25 +{ + /* + * 2.3.25 + * + * 切换到插入排序。 + * 实现一个快速排序,在子数组元素少于 M 时切换到插入排序。 + * 用快速排序处理大小 N 分别为 10^3、10^4、10^5 和 10^6 的随机数组, + * 根据经验给出使其在你的环境中运行速度最快的 M 值。 + * 将 M 从 0 变化到 30 的每个值所得到的平均运行时间绘成曲线。 + * 注意: + * 你需要为算法 2.2 添加一个需要三个参数的 sort() 方法 + * 以使 Insertion.sort(a, lo, hi) 将子数组 a[lo...hi] 排序。 + * + */ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/2 Sorting/2.3/2.3.25/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.25/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a1f18a08c --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("_2._3._25")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("_2._3._25")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("edd5937f-3098-4de4-b1c7-6255bef8f8f1")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.25/Properties/Resources.Designer.cs b/2 Sorting/2.3/2.3.25/Properties/Resources.Designer.cs new file mode 100644 index 000000000..c482eb0bd --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace _2._3._25.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_2._3._25.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 覆盖当前线程的 CurrentUICulture 属性 + /// 使用此强类型的资源类的资源查找。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.25/Properties/Resources.resx b/2 Sorting/2.3/2.3.25/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.25/Properties/Settings.Designer.cs b/2 Sorting/2.3/2.3.25/Properties/Settings.Designer.cs new file mode 100644 index 000000000..96a010247 --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _2._3._25.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.25/Properties/Settings.settings b/2 Sorting/2.3/2.3.25/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/2 Sorting/2.3/2.3.25/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/2 Sorting/2.3/2.3.25/QuickSortInsertion.cs b/2 Sorting/2.3/2.3.25/QuickSortInsertion.cs new file mode 100644 index 000000000..fee0b3e9f --- /dev/null +++ b/2 Sorting/2.3/2.3.25/QuickSortInsertion.cs @@ -0,0 +1,106 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._25 +{ + /// + /// 快速排序类。 + /// + public class QuickSortInsertion : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + /// + /// 默认构造函数。 + /// + public QuickSortInsertion() + { + this.M = 8; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + if (hi - lo <= this.M) + { + // 调用插入排序 + for (int i = lo; i <= hi; i++) + for (int k = i; k > lo && Less(a[k], a[k - 1]); k--) + Exch(a, k, k - 1); + return; + } + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.26/2.3.26.csproj b/2 Sorting/2.3/2.3.26/2.3.26.csproj new file mode 100644 index 000000000..74b39162a --- /dev/null +++ b/2 Sorting/2.3/2.3.26/2.3.26.csproj @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8} + WinExe + _2._3._26 + 2.3.26 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + Form + + + Form2.cs + + + + + + Form1.cs + + + Form2.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.26/App.config b/2 Sorting/2.3/2.3.26/App.config new file mode 100644 index 000000000..1520030ff --- /dev/null +++ b/2 Sorting/2.3/2.3.26/App.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.26/Form1.Designer.cs b/2 Sorting/2.3/2.3.26/Form1.Designer.cs new file mode 100644 index 000000000..dae4970e8 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Form1.Designer.cs @@ -0,0 +1,119 @@ +namespace _2._3._26 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.InputN = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.ErrorLabel = new System.Windows.Forms.Label(); + this.InputM = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(48, 99); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(45, 36); + this.label1.TabIndex = 0; + this.label1.Text = "N:"; + // + // InputN + // + this.InputN.Location = new System.Drawing.Point(99, 96); + this.InputN.Name = "InputN"; + this.InputN.Size = new System.Drawing.Size(100, 44); + this.InputN.TabIndex = 1; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(480, 88); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(157, 58); + this.button1.TabIndex = 2; + this.button1.Text = "绘图"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // ErrorLabel + // + this.ErrorLabel.AutoSize = true; + this.ErrorLabel.ForeColor = System.Drawing.Color.Red; + this.ErrorLabel.Location = new System.Drawing.Point(54, 173); + this.ErrorLabel.Name = "ErrorLabel"; + this.ErrorLabel.Size = new System.Drawing.Size(0, 36); + this.ErrorLabel.TabIndex = 3; + // + // InputM + // + this.InputM.Location = new System.Drawing.Point(260, 96); + this.InputM.Name = "InputM"; + this.InputM.Size = new System.Drawing.Size(100, 44); + this.InputM.TabIndex = 5; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(209, 99); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(49, 36); + this.label2.TabIndex = 4; + this.label2.Text = "M:"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(705, 236); + this.Controls.Add(this.InputM); + this.Controls.Add(this.label2); + this.Controls.Add(this.ErrorLabel); + this.Controls.Add(this.button1); + this.Controls.Add(this.InputN); + this.Controls.Add(this.label1); + this.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Name = "Form1"; + this.Text = "2.3.26"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox InputN; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label ErrorLabel; + private System.Windows.Forms.TextBox InputM; + private System.Windows.Forms.Label label2; + } +} + diff --git a/2 Sorting/2.3/2.3.26/Form1.cs b/2 Sorting/2.3/2.3.26/Form1.cs new file mode 100644 index 000000000..8fac06d28 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Form1.cs @@ -0,0 +1,36 @@ +using System; +using System.Windows.Forms; + +namespace _2._3._26 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + try + { + int N = int.Parse(this.InputN.Text); + int M = int.Parse(this.InputM.Text); + Form2 panel = new Form2(M, N); + panel.ShowDialog(); + } + catch (ArgumentNullException) + { + this.ErrorLabel.Text = "输入值不能为空。"; + } + catch (FormatException) + { + this.ErrorLabel.Text = "格式错误(是否输入了空值?)"; + } + catch (OverflowException) + { + this.ErrorLabel.Text = "数据过大"; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.26/Form1.resx b/2 Sorting/2.3/2.3.26/Form1.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.26/Form2.Designer.cs b/2 Sorting/2.3/2.3.26/Form2.Designer.cs new file mode 100644 index 000000000..9f5ba3dd0 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Form2.Designer.cs @@ -0,0 +1,59 @@ +namespace _2._3._26 +{ + partial class Form2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.SuspendLayout(); + // + // backgroundWorker1 + // + this.backgroundWorker1.WorkerReportsProgress = true; + this.backgroundWorker1.WorkerSupportsCancellation = true; + this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); + this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); + this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); + // + // Form2 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(776, 736); + this.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Name = "Form2"; + this.Text = "绘图结果"; + this.Shown += new System.EventHandler(this.Form2_Shown); + this.ResumeLayout(false); + + } + + #endregion + + private System.ComponentModel.BackgroundWorker backgroundWorker1; + } +} \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.26/Form2.cs b/2 Sorting/2.3/2.3.26/Form2.cs new file mode 100644 index 000000000..2148aec14 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Form2.cs @@ -0,0 +1,114 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Quick; + +namespace _2._3._26 +{ + public partial class Form2 : Form + { + private int M; + private int N; + + public Form2(int m, int n) + { + InitializeComponent(); + this.M = m; + this.N = n; + } + + /// + /// 启动页面时启动后台测试。 + /// + /// + /// + private void Form2_Shown(object sender, EventArgs e) + { + this.Text = "正在绘图"; + this.backgroundWorker1.RunWorkerAsync(); + } + + /// + /// 后台测试方法。 + /// + /// + /// + private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) + { + BackgroundWorker worker = sender as BackgroundWorker; + QuickSortInsertion quickSortInsertion = new QuickSortInsertion + { + M = this.M + }; + int[] data = SortCompare.GetRandomArrayInt(this.N); + worker.ReportProgress(50); + quickSortInsertion.Sort(data); + e.Result = quickSortInsertion.Counts; + } + + /// + /// 更新后台进度方法。 + /// + /// + /// + private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + this.Text = "正在绘图,已完成 " + e.ProgressPercentage + " %"; + } + + /// + /// 测试完毕,进行绘图的方法。 + /// + /// + /// + private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + if (e.Error != null) + { + MessageBox.Show(e.Error.Message); + } + //新建画布 + Graphics graphics = this.CreateGraphics(); + + //翻转默认坐标系 + graphics.TranslateTransform(0, this.Height); + graphics.ScaleTransform(1, -1); + + int[] countsOrigin = e.Result as int[]; + int[] counts = new int[countsOrigin.Length - 1]; + for (int i = 0; i < counts.Length; i++) + { + counts[i] = countsOrigin[i + 1]; + } + + //获取最大值 + double max = counts.Max(); + //计算间距 + double unit = this.Width / (3.0 * counts.Length + 1); + double marginTop = 100; + //计算直方图的矩形 + Rectangle[] rects = new Rectangle[counts.Length]; + rects[0].X = (int)unit; + rects[0].Y = 0; + rects[0].Width = (int)(2 * unit); + rects[0].Height = (int)((counts[0] / max) * (this.Height - marginTop)); + for (int i = 1; i < counts.Length; ++i) + { + rects[i].X = (int)(rects[i - 1].X + 3 * unit); + rects[i].Y = 0; + rects[i].Width = (int)(2 * unit); + rects[i].Height = (int)((counts[i] / (max + 1)) * (this.Height - marginTop)); + } + + //绘图 + graphics.FillRectangles(Brushes.Black, rects); + + //释放资源 + graphics.Dispose(); + + this.Text = "绘图结果,最高次数:" + counts.Max() + " 最低次数:" + counts.Min(); + } + } +} diff --git a/2 Sorting/2.3/2.3.26/Form2.resx b/2 Sorting/2.3/2.3.26/Form2.resx new file mode 100644 index 000000000..59099f264 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Form2.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.26/Program.cs b/2 Sorting/2.3/2.3.26/Program.cs new file mode 100644 index 000000000..72d86d8df --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Program.cs @@ -0,0 +1,29 @@ +using System; +using System.Windows.Forms; + +namespace _2._3._26 +{ + /* + * 2.3.26 + * + * 子数组的大小。 + * 编写一个程序,在快速排序处理大小为 N 的数组的过程中, + * 当子数组的大小小于 M 时,排序方法需要切换为插入排序。 + * 将子数组的大小绘制成直方图。 + * 用 N=10^5,M=10、20 和 50 测试你的程序。 + * + */ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/2 Sorting/2.3/2.3.26/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.26/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..24bf50c3d --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("_2._3._26")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("_2._3._26")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("191f61ae-dba5-4459-bdf3-09c188eceda8")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.26/Properties/Resources.Designer.cs b/2 Sorting/2.3/2.3.26/Properties/Resources.Designer.cs new file mode 100644 index 000000000..da82b2da3 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace _2._3._26.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_2._3._26.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 覆盖当前线程的 CurrentUICulture 属性 + /// 使用此强类型的资源类的资源查找。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.26/Properties/Resources.resx b/2 Sorting/2.3/2.3.26/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.26/Properties/Settings.Designer.cs b/2 Sorting/2.3/2.3.26/Properties/Settings.Designer.cs new file mode 100644 index 000000000..b51f39027 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _2._3._26.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.26/Properties/Settings.settings b/2 Sorting/2.3/2.3.26/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/2 Sorting/2.3/2.3.26/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/2 Sorting/2.3/2.3.26/QuickSortInsertion.cs b/2 Sorting/2.3/2.3.26/QuickSortInsertion.cs new file mode 100644 index 000000000..422206150 --- /dev/null +++ b/2 Sorting/2.3/2.3.26/QuickSortInsertion.cs @@ -0,0 +1,114 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._26 +{ + /// + /// 快速排序类。 + /// + public class QuickSortInsertion : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + public int[] Counts; + + /// + /// 默认构造函数。 + /// + public QuickSortInsertion() + { + this.M = 8; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + this.Counts = new int[this.M + 1]; + for (int i = 0; i < this.M + 1; i++) + { + this.Counts[i] = 0; + } + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + if (hi - lo <= this.M) + { + this.Counts[hi - lo]++; + // 调用插入排序 + for (int i = lo; i <= hi; i++) + for (int k = i; k > lo && Less(a[k], a[k - 1]); k--) + Exch(a, k, k - 1); + return; + } + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.27/2.3.27.csproj b/2 Sorting/2.3/2.3.27/2.3.27.csproj new file mode 100644 index 000000000..a5366406f --- /dev/null +++ b/2 Sorting/2.3/2.3.27/2.3.27.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA} + Exe + _2._3._27 + 2.3.27 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.27/App.config b/2 Sorting/2.3/2.3.27/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.27/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.27/Program.cs b/2 Sorting/2.3/2.3.27/Program.cs new file mode 100644 index 000000000..c050c51f3 --- /dev/null +++ b/2 Sorting/2.3/2.3.27/Program.cs @@ -0,0 +1,57 @@ +using System; +using Quick; + +namespace _2._3._27 +{ + /* + * 2.3.27 + * + * 忽略小数组。 + * 用实验对比以下处理小数组的方法和练习 2.3.25 的处理方法的效果: + * 在快速排序中直接忽略小数组,仅在快速排序结束后运行一次插入排序。 + * 注意: + * 可以通过这些实验估计出电脑的缓存大小, + * 因为当数组大小超出缓存时这种方法的性能可能会下降。 + * + */ + class Program + { + static void Main(string[] args) + { + QuickSortInsertion insertion = new QuickSortInsertion(); + QuickSortIgnore ignore = new QuickSortIgnore(); + int arraySize = 20000; // 初始数组大小。 + const int mSteps = 1; // M 值的递增次数。 + const int trialTimes = 4; // 每次实验的重复次数。 + const int trialLevel = 10; // 双倍递增的次数。 + + Console.WriteLine("M\tn\t\tignore\tinsert\tratio"); + for (int i = 0; i < mSteps; i++) + { + int array = arraySize; + for (int j = 0; j < trialLevel; j++) + { + double timeIgnore = 0; + double timeInsertion = 0; + for (int k = 0; k < trialTimes; k++) + { + int[] a = SortCompare.GetRandomArrayInt(array); + int[] b = new int[a.Length]; + a.CopyTo(b, 0); + timeInsertion += SortCompare.Time(insertion, b); + timeIgnore += SortCompare.Time(ignore, a); + + } + timeIgnore /= trialTimes; + timeInsertion /= trialTimes; + if (arraySize < 10000000) + Console.WriteLine(ignore.M + "\t" + array + "\t\t" + timeIgnore + "\t" + timeInsertion + "\t" + timeIgnore / timeInsertion); + else + Console.WriteLine(ignore.M + "\t" + array + "\t" + timeIgnore + "\t" + timeInsertion + "\t" + timeIgnore / timeInsertion); + array *= 2; + } + ignore.M++; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.27/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.27/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..93ef8830a --- /dev/null +++ b/2 Sorting/2.3/2.3.27/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.27")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.27")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("d95b626c-a04b-4d61-a9b7-16b3edfd2cea")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.27/QuickSortIgnore.cs b/2 Sorting/2.3/2.3.27/QuickSortIgnore.cs new file mode 100644 index 000000000..dc98d4548 --- /dev/null +++ b/2 Sorting/2.3/2.3.27/QuickSortIgnore.cs @@ -0,0 +1,108 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._27 +{ + /// + /// 快速排序类。 + /// + public class QuickSortIgnore : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + /// + /// 默认构造函数。 + /// + public QuickSortIgnore() + { + this.M = 10; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + + // 插入排序处理小数组 + for (int i = 0; i < a.Length; i++) + for (int j = i; j > 0 && Less(a[j], a[j - 1]); j--) + Exch(a, j, j - 1); + + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + if (hi - lo <= this.M) + { + return; // 直接忽略 + } + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.27/QuickSortInsertion.cs b/2 Sorting/2.3/2.3.27/QuickSortInsertion.cs new file mode 100644 index 000000000..6cd0a89f2 --- /dev/null +++ b/2 Sorting/2.3/2.3.27/QuickSortInsertion.cs @@ -0,0 +1,106 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._27 +{ + /// + /// 快速排序类。 + /// + public class QuickSortInsertion : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + /// + /// 默认构造函数。 + /// + public QuickSortInsertion() + { + this.M = 10; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + if (hi - lo <= this.M) + { + // 调用插入排序 + for (int i = lo; i <= hi; i++) + for (int k = i; k > lo && Less(a[k], a[k - 1]); k--) + Exch(a, k, k - 1); + return; + } + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.28/2.3.28.csproj b/2 Sorting/2.3/2.3.28/2.3.28.csproj new file mode 100644 index 000000000..028bb69ab --- /dev/null +++ b/2 Sorting/2.3/2.3.28/2.3.28.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44} + Exe + _2._3._28 + 2.3.28 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.28/App.config b/2 Sorting/2.3/2.3.28/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.28/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.28/Program.cs b/2 Sorting/2.3/2.3.28/Program.cs new file mode 100644 index 000000000..4dd4afddc --- /dev/null +++ b/2 Sorting/2.3/2.3.28/Program.cs @@ -0,0 +1,53 @@ +using System; + +namespace _2._3._28 +{ + /* + * 2.3.28 + * + * 递归深度。 + * 用经验性的研究估计切换阈值为 M 的快速排序 + * 在将大小为 N 的不重复数组排序时的平均递归深度, + * 其中 M=10、20 和 50,N=10^3、10^4、10^5 和 10^6。 + * + */ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("M\tN\tDepth"); + Trial(10); + Trial(20); + Trial(50); + } + + /// + /// 进行一次测试。 + /// + /// 要使用的阈值 + static void Trial(int m) + { + QuickSortInsertion sort = new QuickSortInsertion(); + int trialTime = 5; + + // 由于排序前有 Shuffle,因此直接输入有序数组。 + // M=10 + sort.M = m; + int totalDepth = 0; + for (int N = 1000; N < 10000000; N *= 10) + { + for (int i = 0; i < trialTime; i++) + { + int[] a = new int[N]; + for (int j = 0; j < N; j++) + { + a[j] = j; + } + sort.Sort(a); + totalDepth += sort.Depth; + } + Console.WriteLine(sort.M + "\t" + N + "\t" + totalDepth / trialTime); + } + } + } +} diff --git a/2 Sorting/2.3/2.3.28/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.28/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..537a2e711 --- /dev/null +++ b/2 Sorting/2.3/2.3.28/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.28")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.28")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("ba0fb027-2a8c-4421-bf8b-5e880cb4aa44")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.28/QuickSortInsertion.cs b/2 Sorting/2.3/2.3.28/QuickSortInsertion.cs new file mode 100644 index 000000000..e6b61e578 --- /dev/null +++ b/2 Sorting/2.3/2.3.28/QuickSortInsertion.cs @@ -0,0 +1,113 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._28 +{ + /// + /// 快速排序类。 + /// + public class QuickSortInsertion : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + /// + /// 上一次排序的最大递归深度。 + /// + public int Depth { get; private set; } + + /// + /// 默认构造函数。 + /// + public QuickSortInsertion() + { + this.M = 10; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + /// 递归深度。 + public override void Sort(T[] a) + { + Shuffle(a); + this.Depth = Sort(a, 0, a.Length - 1, 0); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected int Sort(T[] a, int lo, int hi, int depth) where T: IComparable + { + if (hi <= lo) // 别越界 + return depth; + if (hi - lo <= this.M) + { + // 调用插入排序 + for (int i = lo; i <= hi; i++) + for (int k = i; k > lo && Less(a[k], a[k - 1]); k--) + Exch(a, k, k - 1); + return depth; + } + int j = Partition(a, lo, hi); + int left = Sort(a, lo, j - 1, depth + 1); + int right = Sort(a, j + 1, hi, depth + 1); + return Less(left, right) ? right : left; + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.29/2.3.29.csproj b/2 Sorting/2.3/2.3.29/2.3.29.csproj new file mode 100644 index 000000000..ff01b9c51 --- /dev/null +++ b/2 Sorting/2.3/2.3.29/2.3.29.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95} + Exe + _2._3._29 + 2.3.29 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.29/App.config b/2 Sorting/2.3/2.3.29/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.29/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.29/Program.cs b/2 Sorting/2.3/2.3.29/Program.cs new file mode 100644 index 000000000..b75d51d47 --- /dev/null +++ b/2 Sorting/2.3/2.3.29/Program.cs @@ -0,0 +1,78 @@ +using System; +using Quick; + +namespace _2._3._29 +{ + /* + * 2.3.29 + * + * 随机化。 + * 用经验性的研究对比随机选择切分元素和正文所述的一开始就将数组随机化这两种策略的效果。 + * 在子数组大小为 M 时进行切换,将大小为 N 的不重复数组排序, + * 其中 M=10、20 和 50,N=10^3、10^4、10^5 和 10^6。 + * + */ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("M\tN\tshuffle\trandom\tshuffle/random"); + Trial(10); + Trial(20); + Trial(50); + } + + /// + /// 进行一次测试。 + /// + /// 要使用的阈值 + static void Trial(int m) + { + QuickSortInsertion withShuffle = new QuickSortInsertion(); + QuickSortRandomPivot randomPivot = new QuickSortRandomPivot(); + int trialTime = 5; + + // M=10 + withShuffle.M = m; + randomPivot.M = m; + double timeShuffle = 0; + double timeRandomPivot = 0; + for (int N = 1000; N < 10000000; N *= 10) + { + for (int i = 0; i < trialTime; i++) + { + int[] a = new int[N]; + int[] b = new int[N]; + for (int j = 0; j < N; j++) + { + a[j] = j; + } + Shuffle(a); + a.CopyTo(b, 0); + timeShuffle += SortCompare.Time(withShuffle, a); + timeRandomPivot += SortCompare.Time(randomPivot, b); + } + timeShuffle /= trialTime; + timeRandomPivot /= trialTime; + Console.WriteLine(withShuffle.M + "\t" + N + "\t" + timeShuffle + "\t" + timeRandomPivot + "\t" + timeShuffle / timeRandomPivot); + } + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + static void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.29/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.29/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..683971f5e --- /dev/null +++ b/2 Sorting/2.3/2.3.29/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.29")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.29")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("74d02cc1-d0e9-46ed-b6c2-5c6caf0ddf95")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.29/QuickSortInsertion.cs b/2 Sorting/2.3/2.3.29/QuickSortInsertion.cs new file mode 100644 index 000000000..2aa1cb5b4 --- /dev/null +++ b/2 Sorting/2.3/2.3.29/QuickSortInsertion.cs @@ -0,0 +1,106 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._29 +{ + /// + /// 快速排序类。 + /// + public class QuickSortInsertion : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + /// + /// 默认构造函数。 + /// + public QuickSortInsertion() + { + this.M = 10; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + if (hi - lo <= this.M) + { + // 调用插入排序 + for (int i = lo; i <= hi; i++) + for (int k = i; k > lo && Less(a[k], a[k - 1]); k--) + Exch(a, k, k - 1); + return; + } + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.29/QuickSortRandomPivot.cs b/2 Sorting/2.3/2.3.29/QuickSortRandomPivot.cs new file mode 100644 index 000000000..534553f84 --- /dev/null +++ b/2 Sorting/2.3/2.3.29/QuickSortRandomPivot.cs @@ -0,0 +1,95 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._29 +{ + /// + /// 快速排序类。 + /// + public class QuickSortRandomPivot : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + /// + /// 随机数发生器。 + /// + private readonly Random RandomGenerator = new Random(); + + /// + /// 默认构造函数。 + /// + public QuickSortRandomPivot() + { + this.M = 10; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + if (hi - lo <= this.M) + { + // 调用插入排序 + for (int i = lo; i <= hi; i++) + for (int k = i; k > lo && Less(a[k], a[k - 1]); k--) + Exch(a, k, k - 1); + return; + } + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + int pivot = this.RandomGenerator.Next(hi - lo) + lo; + Exch(a, pivot, lo); + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + } +} diff --git a/2 Sorting/2.3/2.3.3/2.3.3.csproj b/2 Sorting/2.3/2.3.3/2.3.3.csproj new file mode 100644 index 000000000..07bf25db2 --- /dev/null +++ b/2 Sorting/2.3/2.3.3/2.3.3.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4} + Exe + _2._3._3 + 2.3.3 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.3/App.config b/2 Sorting/2.3/2.3.3/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.3/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.3/Program.cs b/2 Sorting/2.3/2.3.3/Program.cs new file mode 100644 index 000000000..279bdd6a4 --- /dev/null +++ b/2 Sorting/2.3/2.3.3/Program.cs @@ -0,0 +1,65 @@ +namespace _2._3._3 +{ + /* + * 2.3.3 + * + * 对于长度为 N 的数组, + * 在 Quick.sort() 执行时, + * 其最大元素最多会被交换多少次? + * + */ + class Program + { + static void Main(string[] args) + { + // N / 2 + // 在快速排序中,一个元素要被交换,有以下两种情况 + // 1. 该元素是枢轴,在切分的最后一步被交换 + // 2. 该元素位于枢轴错误的一侧,需要被交换到另一侧去 + // 注意,以上两种情况在一次切分中只会出现一次 + // + // 首先来看第一种情况,如果一个元素变成了枢轴 + // 那么在之后的切分中该元素会被排除,不存在后续的交换。 + // 因此我们的目标应该是: + // 最大的元素总是出现在错误的一侧,同时切分的次数尽可能多。 + // + // 接下来我们来思考如何构造这样的数组 + // 由于我们针对的是最大的元素,因此「错误的一侧」就是枢轴的左侧。 + // 为了使切分的次数尽可能多,我们需要保持最大值移动的距离尽量短。 + // 但如果每次只移动一位的话,下一次切分时最大值就会变成枢轴 + // 例如 4 10 3 5 6,枢轴为 4,交换后数组变为: + // 4 3 10 5 6 + // 随后 4 和 3 交换 + // 3 4 10 5 6 + // 下一次切分时 10 会变成枢轴,不再参与后续的切分。 + // 因此我们需要让最大值每次移动两个元素。 + // + // 考虑下面的数组: + // 2 10 4 1 6 3 8 5 7 9 + // 第一次切分的时候,枢轴为 2,10 和 1 进行交换 + // 数组变为: + // 2 1 4 10 6 3 8 5 7 9 + // 随后枢轴交换,数组变为: + // 1 2 4 10 6 3 8 5 7 9 + // 第二次切分,枢轴为 4,10 和 3 进行交换。 + // 1 2 4 3 6 10 8 5 7 9 + // 随后枢轴交换 数组变为: + // 1 2 3 4 6 10 8 5 7 9 + // 第三次切分,枢轴为 6,10 和 5 交换 + // 1 2 3 4 6 5 8 10 7 9 + // 随后枢轴交换,数组变为: + // 1 2 3 4 5 6 8 10 7 9 + // 第四次切分,枢轴为 8,10 和 7 交换 + // 1 2 3 4 5 6 8 7 10 9 + // 枢轴交换,数组变为 + // 1 2 3 4 5 6 7 8 10 9 + // 最后一次切分,枢轴为 10,直接交换 + // 1 2 3 4 5 6 7 8 9 10 + // + // 我们可以总结出要构造这样的数组的模板 + // a2 max a3 a1 + // 其中 a1 < a2 < a3 < max + // max 每轮切分移动两格,总共切分 N/2 次。 + } + } +} diff --git a/2 Sorting/2.3/2.3.3/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.3/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..af231497b --- /dev/null +++ b/2 Sorting/2.3/2.3.3/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.3")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.3")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("b4cb8167-e055-43ef-b61f-744f0a2bb7f4")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.30/2.3.30.csproj b/2 Sorting/2.3/2.3.30/2.3.30.csproj new file mode 100644 index 000000000..407945434 --- /dev/null +++ b/2 Sorting/2.3/2.3.30/2.3.30.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D} + Exe + _2._3._30 + 2.3.30 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.30/App.config b/2 Sorting/2.3/2.3.30/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.30/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.30/Program.cs b/2 Sorting/2.3/2.3.30/Program.cs new file mode 100644 index 000000000..2f8f7d6ed --- /dev/null +++ b/2 Sorting/2.3/2.3.30/Program.cs @@ -0,0 +1,186 @@ +using System; +using Quick; + +namespace _2._3._30 +{ + /* + * 2.3.30 + * + * 极端情况。 + * 用初始随机化和非初始随机化的快速排序测试练习 2.1.35 和练习 2.1.36 中描述的大型非随机数组。 + * 在将这些大数组排序时,乱序对快速排序的性能有何影响? + * + */ + class Program + { + static void Main(string[] args) + { + QuickSortInsertion insertionSort = new QuickSortInsertion(); + QuickSortRandomPivot randomSort = new QuickSortRandomPivot(); + int n = 5000000; + + // 高斯分布(正态分布) + double[] arrayInsertion = SortCompare.GetNormalDistributionArray(n); + double[] arraySelection = new double[n]; + + arrayInsertion.CopyTo(arraySelection, 0); + + Console.WriteLine("Normal Distribution:"); + Console.WriteLine("Insertion: " + SortCompare.Time(insertionSort, arrayInsertion)); + Console.WriteLine("Random Pivot: " + SortCompare.Time(randomSort, arraySelection)); + Console.WriteLine(); + + // 泊松分布 + arrayInsertion = SortCompare.GetPossionDistributionArray(n); + arrayInsertion.CopyTo(arraySelection, 0); + + Console.WriteLine("Poission Distribution:"); + Console.WriteLine("Insertion: " + SortCompare.Time(insertionSort, arrayInsertion)); + Console.WriteLine("Random Pivot: " + SortCompare.Time(randomSort, arraySelection)); + Console.WriteLine(); + + // 几何分布 + arrayInsertion = SortCompare.GetGeometricDistributionArray(n, 0.3); + arrayInsertion.CopyTo(arraySelection, 0); + + Console.WriteLine("Geometric Distribution:"); + Console.WriteLine("Insertion: " + SortCompare.Time(insertionSort, arrayInsertion)); + Console.WriteLine("Random Pivot: " + SortCompare.Time(randomSort, arraySelection)); + Console.WriteLine(); + + // 离散分布 + arrayInsertion = SortCompare.GetDiscretDistributionArray(n, new double[] { 0.1, 0.2, 0.3, 0.1, 0.1, 0.1, 0.1 }); + arrayInsertion.CopyTo(arraySelection, 0); + + Console.WriteLine("Discret Distribution:"); + Console.WriteLine("Insertion: " + SortCompare.Time(insertionSort, arrayInsertion)); + Console.WriteLine("Random Pivot: " + SortCompare.Time(randomSort, arraySelection)); + Console.WriteLine(); + + // 一半是 0 一半是 1 + int[] arrayNormalInsertion = HalfZeroHalfOne(n); + int[] arrayRandomPivot = new int[n]; + arrayNormalInsertion.CopyTo(arrayRandomPivot, 0); + + Console.WriteLine("half 0 and half 1"); + Console.WriteLine("Insertion:" + SortCompare.Time(insertionSort, arrayNormalInsertion)); + Console.WriteLine("Random Pivot:" + SortCompare.Time(randomSort, arrayRandomPivot)); + Console.WriteLine(); + + // 一半是 0, 1/4 是 1, 1/8 是 2…… + arrayNormalInsertion = HalfAndHalf(n); + arrayNormalInsertion.CopyTo(arrayRandomPivot, 0); + + Console.WriteLine("half and half and half ..."); + Console.WriteLine("Insertion Sort:" + SortCompare.Time(insertionSort, arrayNormalInsertion)); + Console.WriteLine("Random Pivot:" + SortCompare.Time(randomSort, arrayRandomPivot)); + Console.WriteLine(); + + // 一半是 0,一半是随机 int 值 + arrayNormalInsertion = HalfZeroHalfRandom(n); + arrayNormalInsertion.CopyTo(arrayRandomPivot, 0); + + Console.WriteLine("half 0 half random"); + Console.WriteLine("Insertion Sort:" + SortCompare.Time(insertionSort, arrayNormalInsertion)); + Console.WriteLine("Random Pivot:" + SortCompare.Time(randomSort, arrayRandomPivot)); + } + + /// + /// 获取一半是 0 一半是 1 的随机 数组。 + /// + /// 数组大小。 + /// 一半是 0 一半是 1 的 数组。 + static int[] HalfZeroHalfOne(int n) + { + int[] result = new int[n]; + Random random = new Random(); + for (int i = 0; i < n; i++) + { + if (random.NextDouble() >= 0.5) + { + result[i] = 0; + } + else + { + result[i] = 1; + } + } + return result; + } + + /// + /// 生成 1/2 为 0, 1/4 为 1, 1/8 为 2 …… 的 数组。 + /// + /// 数组长度。 + /// 1/2 为 0, 1/4 为 1, 1/8 为 2 …… 的 数组。 + static int[] HalfAndHalf(int n) + { + int[] array = new int[n]; + HalfIt(0, 0, n / 2, array); + Shuffle(array); + return array; + } + + /// + /// 递归生成 1/2 为 0, 1/4 为 1, 1/8 为 2 …… 的 数组。 + /// + /// 填充起点。 + /// 起始编号。 + /// 填充长度 + /// 用于填充的数组。 + /// 一个 数组。 + static int[] HalfIt(int start, int number, int length, int[] array) + { + if (length == 0) + return array; + + for (int i = 0; i < length; i++) + { + array[start + i] = number; + } + + return HalfIt(start + length, number + 1, length / 2, array); + } + + /// + /// 生成一半是 0 一半是随机整数的 数组。 + /// + /// 数组大小。 + /// 生成一半是 0 一半是随机整数的 数组。 + static int[] HalfZeroHalfRandom(int n) + { + int[] array = new int[n]; + Random random = new Random(); + for (int i = 0; i < n / 2; i++) + { + array[i] = 0; + } + + for (int i = n / 2; i < n; i++) + { + array[i] = random.Next(); + } + + Shuffle(array); + + return array; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组。 + static void Shuffle(int[] a) + { + int N = a.Length; + Random random = new Random(); + for (int i = 0; i < N; i++) + { + int r = i + random.Next(N - i);// 等于StdRandom.uniform(N-i) + int temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.30/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.30/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..e70d0dd30 --- /dev/null +++ b/2 Sorting/2.3/2.3.30/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.30")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.30")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("dbaff6e5-b894-4995-9c1f-5a6c830a933d")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.30/QuickSortInsertion.cs b/2 Sorting/2.3/2.3.30/QuickSortInsertion.cs new file mode 100644 index 000000000..7834c4a64 --- /dev/null +++ b/2 Sorting/2.3/2.3.30/QuickSortInsertion.cs @@ -0,0 +1,106 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._30 +{ + /// + /// 快速排序类。 + /// + public class QuickSortInsertion : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + /// + /// 默认构造函数。 + /// + public QuickSortInsertion() + { + this.M = 10; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + if (hi - lo <= this.M) + { + // 调用插入排序 + for (int i = lo; i <= hi; i++) + for (int k = i; k > lo && Less(a[k], a[k - 1]); k--) + Exch(a, k, k - 1); + return; + } + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.30/QuickSortRandomPivot.cs b/2 Sorting/2.3/2.3.30/QuickSortRandomPivot.cs new file mode 100644 index 000000000..2358031a8 --- /dev/null +++ b/2 Sorting/2.3/2.3.30/QuickSortRandomPivot.cs @@ -0,0 +1,95 @@ +using System; +using System.Diagnostics; +using Quick; + +namespace _2._3._30 +{ + /// + /// 快速排序类。 + /// + public class QuickSortRandomPivot : BaseSort + { + /// + /// 切换到插入排序的阈值。 + /// + public int M { get; set; } + + /// + /// 随机数发生器。 + /// + private readonly Random RandomGenerator = new Random(); + + /// + /// 默认构造函数。 + /// + public QuickSortRandomPivot() + { + this.M = 10; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + if (hi - lo <= this.M) + { + // 调用插入排序 + for (int i = lo; i <= hi; i++) + for (int k = i; k > lo && Less(a[k], a[k - 1]); k--) + Exch(a, k, k - 1); + return; + } + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + int pivot = this.RandomGenerator.Next(hi - lo) + lo; + Exch(a, pivot, lo); + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + } +} diff --git a/2 Sorting/2.3/2.3.31/2.3.31.csproj b/2 Sorting/2.3/2.3.31/2.3.31.csproj new file mode 100644 index 000000000..841524e98 --- /dev/null +++ b/2 Sorting/2.3/2.3.31/2.3.31.csproj @@ -0,0 +1,97 @@ + + + + + Debug + AnyCPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2} + WinExe + _2._3._31 + 2.3.31 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + Form + + + Form2.cs + + + + + Form1.cs + + + Form2.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.31/App.config b/2 Sorting/2.3/2.3.31/App.config new file mode 100644 index 000000000..1520030ff --- /dev/null +++ b/2 Sorting/2.3/2.3.31/App.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.31/Form1.Designer.cs b/2 Sorting/2.3/2.3.31/Form1.Designer.cs new file mode 100644 index 000000000..b6fc8b705 --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Form1.Designer.cs @@ -0,0 +1,119 @@ +namespace _2._3._31 +{ + partial class Form1 + { + /// + /// 必需的设计器变量。 + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 清理所有正在使用的资源。 + /// + /// 如果应释放托管资源,为 true;否则为 false。 + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows 窗体设计器生成的代码 + + /// + /// 设计器支持所需的方法 - 不要修改 + /// 使用代码编辑器修改此方法的内容。 + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.InputN = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.ErrorLabel = new System.Windows.Forms.Label(); + this.InputT = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(48, 99); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(45, 36); + this.label1.TabIndex = 0; + this.label1.Text = "N:"; + // + // InputN + // + this.InputN.Location = new System.Drawing.Point(99, 96); + this.InputN.Name = "InputN"; + this.InputN.Size = new System.Drawing.Size(172, 44); + this.InputN.TabIndex = 1; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(480, 88); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(157, 58); + this.button1.TabIndex = 5; + this.button1.Text = "绘图"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // ErrorLabel + // + this.ErrorLabel.AutoSize = true; + this.ErrorLabel.ForeColor = System.Drawing.Color.Red; + this.ErrorLabel.Location = new System.Drawing.Point(54, 173); + this.ErrorLabel.Name = "ErrorLabel"; + this.ErrorLabel.Size = new System.Drawing.Size(0, 36); + this.ErrorLabel.TabIndex = 3; + // + // InputT + // + this.InputT.Location = new System.Drawing.Point(328, 96); + this.InputT.Name = "InputT"; + this.InputT.Size = new System.Drawing.Size(100, 44); + this.InputT.TabIndex = 2; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(277, 99); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(38, 36); + this.label2.TabIndex = 4; + this.label2.Text = "T:"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(705, 236); + this.Controls.Add(this.InputT); + this.Controls.Add(this.label2); + this.Controls.Add(this.ErrorLabel); + this.Controls.Add(this.button1); + this.Controls.Add(this.InputN); + this.Controls.Add(this.label1); + this.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Name = "Form1"; + this.Text = "2.3.31"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox InputN; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label ErrorLabel; + private System.Windows.Forms.TextBox InputT; + private System.Windows.Forms.Label label2; + } +} + diff --git a/2 Sorting/2.3/2.3.31/Form1.cs b/2 Sorting/2.3/2.3.31/Form1.cs new file mode 100644 index 000000000..5db0dd0d9 --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Form1.cs @@ -0,0 +1,36 @@ +using System; +using System.Windows.Forms; + +namespace _2._3._31 +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void button1_Click(object sender, EventArgs e) + { + try + { + int N = int.Parse(this.InputN.Text); + int T = int.Parse(this.InputT.Text); + Form2 panel = new Form2(N, T); + panel.ShowDialog(); + } + catch (ArgumentNullException) + { + this.ErrorLabel.Text = "输入值不能为空。"; + } + catch (FormatException) + { + this.ErrorLabel.Text = "格式错误(是否输入了空值?)"; + } + catch (OverflowException) + { + this.ErrorLabel.Text = "数据过大"; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.31/Form1.resx b/2 Sorting/2.3/2.3.31/Form1.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.31/Form2.Designer.cs b/2 Sorting/2.3/2.3.31/Form2.Designer.cs new file mode 100644 index 000000000..11db8368f --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Form2.Designer.cs @@ -0,0 +1,59 @@ +namespace _2._3._31 +{ + partial class Form2 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.SuspendLayout(); + // + // backgroundWorker1 + // + this.backgroundWorker1.WorkerReportsProgress = true; + this.backgroundWorker1.WorkerSupportsCancellation = true; + this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); + this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); + this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); + // + // Form2 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(168F, 168F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(776, 736); + this.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.Name = "Form2"; + this.Text = "绘图结果"; + this.Shown += new System.EventHandler(this.Form2_Shown); + this.ResumeLayout(false); + + } + + #endregion + + private System.ComponentModel.BackgroundWorker backgroundWorker1; + } +} \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.31/Form2.cs b/2 Sorting/2.3/2.3.31/Form2.cs new file mode 100644 index 000000000..74c77a6ff --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Form2.cs @@ -0,0 +1,113 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; +using Quick; + +namespace _2._3._31 +{ + public partial class Form2 : Form + { + private int N; + private int T; + + public Form2(int n, int t) + { + InitializeComponent(); + this.N = n; + this.T = t; + } + + /// + /// 启动页面时启动后台测试。 + /// + /// + /// + private void Form2_Shown(object sender, EventArgs e) + { + this.Text = "正在绘图"; + this.backgroundWorker1.RunWorkerAsync(); + } + + /// + /// 后台测试方法。 + /// + /// + /// + private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) + { + BackgroundWorker worker = sender as BackgroundWorker; + QuickSort quick = new QuickSort(); + + double percentPerTrial = 100.0 / this.T; + double[] totalTime = new double[this.T]; + for (int i = 0; i < this.T; i++) + { + double[] data = SortCompare.GetRandomArrayDouble(this.N); + totalTime[i] = SortCompare.Time(quick, data); + worker.ReportProgress((int)(percentPerTrial * i)); + } + + e.Result = totalTime; + } + + /// + /// 更新后台进度方法。 + /// + /// + /// + private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + this.Text = "正在测试,已完成 " + e.ProgressPercentage + " %"; + } + + /// + /// 测试完毕,进行绘图的方法。 + /// + /// + /// + private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + if (e.Error != null) + { + MessageBox.Show(e.Error.Message); + } + //新建画布 + Graphics graphics = this.CreateGraphics(); + + //翻转默认坐标系 + graphics.TranslateTransform(0, this.Height); + graphics.ScaleTransform(1, -1); + + double[] counts = e.Result as double[]; + + //获取最大值 + double max = counts.Max(); + //计算间距 + double unit = this.Width / (3.0 * counts.Length + 1); + double marginTop = 100; + //计算直方图的矩形 + Rectangle[] rects = new Rectangle[counts.Length]; + rects[0].X = (int)unit; + rects[0].Y = 0; + rects[0].Width = (int)(2 * unit); + rects[0].Height = (int)((counts[0] / max) * (this.Height - marginTop)); + for (int i = 1; i < counts.Length; ++i) + { + rects[i].X = (int)(rects[i - 1].X + 3 * unit); + rects[i].Y = 0; + rects[i].Width = (int)(2 * unit); + rects[i].Height = (int)((counts[i] / (max + 1)) * (this.Height - marginTop)); + } + + //绘图 + graphics.FillRectangles(Brushes.Black, rects); + + //释放资源 + graphics.Dispose(); + + this.Text = "绘图结果,最高耗时:" + counts.Max() + " 最低耗时:" + counts.Min(); + } + } +} diff --git a/2 Sorting/2.3/2.3.31/Form2.resx b/2 Sorting/2.3/2.3.31/Form2.resx new file mode 100644 index 000000000..59099f264 --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Form2.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.31/Program.cs b/2 Sorting/2.3/2.3.31/Program.cs new file mode 100644 index 000000000..818447f87 --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Windows.Forms; + +namespace _2._3._31 +{ + /* + * 2.3.31 + * + * 运行时间直方图。 + * 编写一个程序,接受命令行参数 N 和 T, + * 用快速排序对大小为 N 的随机浮点数数组进行 T 次排序, + * 并将所有运行时间绘制成直方图。 + * 令 N=10^3、10^4、10^5 和 10^6, + * 为了使曲线更平滑,T 值越大越好。 + * 这个练习最关键的地方在于找到适当的比例绘制出实验结果。 + * + */ + static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/2 Sorting/2.3/2.3.31/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.31/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a1daf150b --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("_2._3._31")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("_2._3._31")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("de2e396c-e48b-4414-a12c-f4ad0e4587c2")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.31/Properties/Resources.Designer.cs b/2 Sorting/2.3/2.3.31/Properties/Resources.Designer.cs new file mode 100644 index 000000000..3600bb856 --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace _2._3._31.Properties +{ + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_2._3._31.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 覆盖当前线程的 CurrentUICulture 属性 + /// 使用此强类型的资源类的资源查找。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.31/Properties/Resources.resx b/2 Sorting/2.3/2.3.31/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.31/Properties/Settings.Designer.cs b/2 Sorting/2.3/2.3.31/Properties/Settings.Designer.cs new file mode 100644 index 000000000..e5d807503 --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _2._3._31.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.31/Properties/Settings.settings b/2 Sorting/2.3/2.3.31/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/2 Sorting/2.3/2.3.31/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/2 Sorting/2.3/2.3.4/2.3.4.csproj b/2 Sorting/2.3/2.3.4/2.3.4.csproj new file mode 100644 index 000000000..38e610497 --- /dev/null +++ b/2 Sorting/2.3/2.3.4/2.3.4.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {387D908B-19C8-4CF8-828D-D244C85872B3} + Exe + _2._3._4 + 2.3.4 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.4/App.config b/2 Sorting/2.3/2.3.4/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.4/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.4/Program.cs b/2 Sorting/2.3/2.3.4/Program.cs new file mode 100644 index 000000000..8da7b87d3 --- /dev/null +++ b/2 Sorting/2.3/2.3.4/Program.cs @@ -0,0 +1,41 @@ +using System; +using Quick; + +namespace _2._3._4 +{ + /* + * 2.3.4 + * + * 假如跳过开头打乱数组的操作,给出六个含有 10 个元素的数组, + * 使得 Quick.sort() 所需的比较次数达到最坏情况。 + * + */ + class Program + { + static void Main(string[] args) + { + // 每次只让枢轴变为已排序,这就是最坏情况。 + // 这种时候枢轴是当前子数组的最大值/最小值。 + // 由于在我们的实现中总是取子数组的第一个元素作为枢轴。 + // 因此一个已排序的数组可以达到最坏情况,比较次数达到 O(n^2)。 + // 如果换作取最后一个元素,最坏情况会变成逆序数组。 + // 我们的实现中如果碰到与枢轴相等的元素也会停止循环, + // 因此如果数组中有重复的元素会减少比较次数。 + // + // 答案: + // 1 2 3 4 5 6 7 8 9 10 + // 2 3 4 5 6 7 8 9 10 11 + // 3 4 5 6 7 8 9 10 11 12 + // 4 5 6 7 8 9 10 11 12 13 + // 5 6 7 8 9 10 11 12 13 14 + // 6 7 8 9 10 11 12 13 14 15 + QuickSortAnalyze quick = new QuickSortAnalyze + { + NeedShuffle = false // 关闭开始的打乱操作。 + }; + int[] a = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + quick.Sort(a); + Console.WriteLine(quick.CompareCount); + } + } +} diff --git a/2 Sorting/2.3/2.3.4/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.4/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..b1dc45933 --- /dev/null +++ b/2 Sorting/2.3/2.3.4/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.4")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.4")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("387d908b-19c8-4cf8-828d-d244c85872b3")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.5/2.3.5.csproj b/2 Sorting/2.3/2.3.5/2.3.5.csproj new file mode 100644 index 000000000..83a2ee36f --- /dev/null +++ b/2 Sorting/2.3/2.3.5/2.3.5.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {324869E0-1699-46CA-BF4E-E99954BE4B98} + Exe + _2._3._5 + 2.3.5 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.5/App.config b/2 Sorting/2.3/2.3.5/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.5/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.5/Program.cs b/2 Sorting/2.3/2.3.5/Program.cs new file mode 100644 index 000000000..2e161d6f5 --- /dev/null +++ b/2 Sorting/2.3/2.3.5/Program.cs @@ -0,0 +1,26 @@ +using System; +using Quick; + +namespace _2._3._5 +{ + /* + * 2.3.5 + * + * 给出一段代码将已知只有两种主键值的数组排序。 + * + */ + class Program + { + static void Main(string[] args) + { + Sort2Distinct sort2Distinct = new Sort2Distinct(); + int[] a = new int[] { 2, 1, 2, 2, 1, 2, 1, 2, 1, 1 }; + sort2Distinct.Sort(a); + for (int i = 0; i < a.Length; i++) + { + Console.Write(a[i] + " "); + } + Console.WriteLine(); + } + } +} diff --git a/2 Sorting/2.3/2.3.5/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.5/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1c8967595 --- /dev/null +++ b/2 Sorting/2.3/2.3.5/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.5")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.5")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("324869e0-1699-46ca-bf4e-e99954be4b98")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.6/2.3.6.csproj b/2 Sorting/2.3/2.3.6/2.3.6.csproj new file mode 100644 index 000000000..88d47bc28 --- /dev/null +++ b/2 Sorting/2.3/2.3.6/2.3.6.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621} + Exe + _2._3._6 + 2.3.6 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.6/App.config b/2 Sorting/2.3/2.3.6/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.6/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.6/Program.cs b/2 Sorting/2.3/2.3.6/Program.cs new file mode 100644 index 000000000..93598f41b --- /dev/null +++ b/2 Sorting/2.3/2.3.6/Program.cs @@ -0,0 +1,42 @@ +using System; +using Quick; + +namespace _2._3._6 +{ + /* + * 2.3.6 + * + * 编写一段代码来计算 C_N 的准确值, + * 在 N=100、1000 和 10 000 的情况下比较准确值和估计值 2NlnN 的差距。 + * + */ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("N\t准确值\t估计值\t比值"); + QuickSortAnalyze sort = new QuickSortAnalyze(); + int N = 100; + int trialTime = 500; + for (int i = 0; i < 3; i++) + { + int sumOfCompare = 0; + int[] a = new int[N]; + for (int j = 0; j < trialTime; j++) + { + for (int k = 0; k < N; k++) + { + a[k] = k; + } + SortCompare.Shuffle(a); + sort.Sort(a); + sumOfCompare += sort.CompareCount; + } + int averageCompare = sumOfCompare / trialTime; + double estimatedCompare = 2 * N * Math.Log(N); + Console.WriteLine(N + "\t" + averageCompare + "\t" + (int)estimatedCompare + "\t" + averageCompare / estimatedCompare); + N *= 10; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.6/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.6/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..882d845b5 --- /dev/null +++ b/2 Sorting/2.3/2.3.6/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.6")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.6")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("601fc4eb-6b24-4ef5-835d-9940a8ec6621")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.7/2.3.7.csproj b/2 Sorting/2.3/2.3.7/2.3.7.csproj new file mode 100644 index 000000000..efdaee0c3 --- /dev/null +++ b/2 Sorting/2.3/2.3.7/2.3.7.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9} + Exe + _2._3._7 + 2.3.7 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.7/App.config b/2 Sorting/2.3/2.3.7/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.7/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.7/Program.cs b/2 Sorting/2.3/2.3.7/Program.cs new file mode 100644 index 000000000..c3017ef55 --- /dev/null +++ b/2 Sorting/2.3/2.3.7/Program.cs @@ -0,0 +1,64 @@ +using System; +using Quick; + +namespace _2._3._7 +{ + /* + * 2.3.7 + * + * 在使用快速排序将 N 个不重复的元素排序时, + * 计算大小为 0、1 和 2 的子数组的数量。 + * 如果你喜欢数学,请推导; + * 如果你不喜欢,请做一些实验并提出猜想。 + * + */ + class Program + { + static void Main(string[] args) + { + // 证明 + // 我们设 C0(n) 代表将 n 个不重复元素排序时大小为 0 的数组的数量。 + // 同理有 C1(n) 和 C2(n) 代表大小为 1 的数组的数量和大小为 2 的数组的数量。 + // 设 k 代表切分位置,显然切分位置随机且概率相等,在 1~n 之间均匀分布。 + // 根据条件,三者都满足下式。 + // C(n) = 1/n sum(C(k - 1) + C(n - k)), k=1,2,...,n + // 显然 sum(C(k - 1)) = sum(C(n - k)), k=1,2,...,n + // 于是可以化简为 + // C(n) = 2/n sum(C(k - 1)), k=1,2,...,n + // nC(n) = 2 * sum(C(k-1)), k=1,2,...,n + // 同理有 + // (n-1)C(n-1) = 2 * sum(C(k-1)), k = 1,2,...,n-1 + // 相减得到递推式 + // nC(n) - (n-1)C(n-1) = 2*C(n-1) + // C(n) = (n+1)/n * C(n-1) + // 利用累乘法可以求得通项公式 + // C(n)=C(k)*(n+1)/(k+1), n>k + // 对于 C0 有 C0(0)=1, C0(1)=0 + // C0(2)=C(0)+C(1)=1 + // C0(n)=(n+1)/3, n>2 + // 对于 C1 有 C1(0)=0, C1(1)=1 + // C1(2)=C1(0)+C1(1)=1 + // C1(n)=(n+1)/3, n>2 + // 对于 C2 有 C2(0)=C2(1)=0, C2(2)=1 + // C2(3)=1/3*2*(C2(0)+C2(1)+C2(2))=2/3 + // C2(n)=C2(3)*(n+1)/4=(n+1)/6, n>3 + // 结论 + // C0(n)=C1(n)=(n+1)/3, C2(n)=(n+1)/6 + int n = 1000; + QuickSortAnalyze sort = new QuickSortAnalyze(); + Console.WriteLine("n\t0\t1\t2"); + for (int i = 0; i < 5; i++) + { + int[] a = new int[n]; + for (int j = 0; j < n; j++) + { + a[j] = j; + } + SortCompare.Shuffle(a); + sort.Sort(a); + Console.WriteLine(n + "\t" + sort.Array0Num + "\t" + sort.Array1Num + "\t" + sort.Array2Num); + n *= 2; + } + } + } +} diff --git a/2 Sorting/2.3/2.3.7/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.7/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..f41e4a716 --- /dev/null +++ b/2 Sorting/2.3/2.3.7/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.7")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.7")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("426b6f5b-cf6f-4f06-88d7-de5b658fd2c9")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.8/2.3.8.csproj b/2 Sorting/2.3/2.3.8/2.3.8.csproj new file mode 100644 index 000000000..97efddac8 --- /dev/null +++ b/2 Sorting/2.3/2.3.8/2.3.8.csproj @@ -0,0 +1,58 @@ + + + + + Debug + AnyCPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4} + Exe + _2._3._8 + 2.3.8 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {f5fb1710-8260-4d0b-a366-eff40e64381f} + Quick + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.8/App.config b/2 Sorting/2.3/2.3.8/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.8/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.8/Program.cs b/2 Sorting/2.3/2.3.8/Program.cs new file mode 100644 index 000000000..1e557f2b6 --- /dev/null +++ b/2 Sorting/2.3/2.3.8/Program.cs @@ -0,0 +1,34 @@ +using System; +using Quick; + +namespace _2._3._8 +{ + /* + * 2.3.8 + * + * Quick.sort() 在处理 N 个全部重复的元素时大约需要多少次比较? + * + */ + class Program + { + static void Main(string[] args) + { + // 约为 NlogN 次 + QuickSortAnalyze sort = new QuickSortAnalyze(); + int N = 100; + Console.WriteLine("N\tCompare\tNlogN"); + for (int i = 0; i < 4; i++) + { + int[] a = new int[N]; + for (int j = 0; j < a.Length; j++) + { + a[j] = 1; + } + sort.Sort(a); + Console.WriteLine(N + "\t" + sort.CompareCount + "\t" + N * Math.Log(N) / Math.Log(2)); + N *= 10; + } + + } + } +} diff --git a/2 Sorting/2.3/2.3.8/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.8/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..c0bb8b6fe --- /dev/null +++ b/2 Sorting/2.3/2.3.8/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.8")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.8")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("69cdeb12-6317-46c1-9def-f5946dde9ad4")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.9/2.3.9.csproj b/2 Sorting/2.3/2.3.9/2.3.9.csproj new file mode 100644 index 000000000..f5275fda6 --- /dev/null +++ b/2 Sorting/2.3/2.3.9/2.3.9.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {49630892-92E5-42A0-A76B-5A84BFACBB59} + Exe + _2._3._9 + 2.3.9 + v4.7 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.9/App.config b/2 Sorting/2.3/2.3.9/App.config new file mode 100644 index 000000000..016d28fcc --- /dev/null +++ b/2 Sorting/2.3/2.3.9/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/2.3.9/Program.cs b/2 Sorting/2.3/2.3.9/Program.cs new file mode 100644 index 000000000..768f447e3 --- /dev/null +++ b/2 Sorting/2.3/2.3.9/Program.cs @@ -0,0 +1,25 @@ +namespace _2._3._9 +{ + /* + * 2.3.9 + * + * 请说明 Quick.sort() 在处理只有两种主键值时的行为, + * 以及在处理只有三种主键值的数组时的行为。 + * + */ + class Program + { + static void Main(string[] args) + { + // 切分时,枢轴左侧都是小于(或等于)枢轴的, + // 右侧都是大于(或等于)枢轴的 + // 只有两种主键值时, + // 第一次切分之后,某一侧的元素将全部相同 + // (如果枢轴选了较大的,那么右侧将全部相同,反之则左侧全部相同) + // + // 只有三种主键值时,和一般快速排序并无不同。 + // 但如果第一次切分时选择了中间值作为枢轴,且中间值只有一个 + // 那么只需要一次切分数组便会有序。 + } + } +} diff --git a/2 Sorting/2.3/2.3.9/Properties/AssemblyInfo.cs b/2 Sorting/2.3/2.3.9/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..ee4c3ebc2 --- /dev/null +++ b/2 Sorting/2.3/2.3.9/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("2.3.9")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("2.3.9")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("49630892-92e5-42a0-a76b-5a84bfacbb59")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +// 方法是按如下所示使用“*”: : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/2.3.sln b/2 Sorting/2.3/2.3.sln new file mode 100644 index 000000000..0c4438bf2 --- /dev/null +++ b/2 Sorting/2.3/2.3.sln @@ -0,0 +1,253 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2035 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1-基础题(2.3.1~2.3.14)", "1-基础题(2.3.1~2.3.14)", "{70D79B29-6263-4137-A094-75EDE650959B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2-提高题(2.3.15~2.3.24)", "2-提高题(2.3.15~2.3.24)", "{7FC73184-7437-434A-9339-C190965ADC9D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3-实验题(2.3.25~2.3.31)", "3-实验题(2.3.25~2.3.31)", "{2D8A0264-3D6B-4523-94BE-1E396CDB077C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "0-类库", "0-类库", "{E15F04CF-E19C-46F1-BDAC-26332BAEB27A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quick", "Quick\Quick.csproj", "{F5FB1710-8260-4D0B-A366-EFF40E64381F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.1", "2.3.1\2.3.1.csproj", "{0B42B539-F300-4D97-B4D0-47249CCC6F01}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.2", "2.3.2\2.3.2.csproj", "{C713169E-361B-4DF3-BCCA-68740199FF52}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.3", "2.3.3\2.3.3.csproj", "{B4CB8167-E055-43EF-B61F-744F0A2BB7F4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.4", "2.3.4\2.3.4.csproj", "{387D908B-19C8-4CF8-828D-D244C85872B3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.5", "2.3.5\2.3.5.csproj", "{324869E0-1699-46CA-BF4E-E99954BE4B98}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.6", "2.3.6\2.3.6.csproj", "{601FC4EB-6B24-4EF5-835D-9940A8EC6621}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.7", "2.3.7\2.3.7.csproj", "{426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.8", "2.3.8\2.3.8.csproj", "{69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.9", "2.3.9\2.3.9.csproj", "{49630892-92E5-42A0-A76B-5A84BFACBB59}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.10", "2.3.10\2.3.10.csproj", "{A084203F-4C71-4A74-9D8B-F76EFD052845}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.11", "2.3.11\2.3.11.csproj", "{14D53C1D-F1DF-4826-9063-A087C55B289B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.12", "2.3.12\2.3.12.csproj", "{4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.13", "2.3.13\2.3.13.csproj", "{EE14928B-180C-41DE-B6DE-F645F919C152}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.14", "2.3.14\2.3.14.csproj", "{8C16556D-9644-47C3-B88F-648C53FF0701}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.15", "2.3.15\2.3.15.csproj", "{277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.16", "2.3.16\2.3.16.csproj", "{691244C9-0DE3-4DB8-B11E-BCA70985C883}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.17", "2.3.17\2.3.17.csproj", "{A5BAAA13-8458-43F8-B7A3-7E37F074832B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.18", "2.3.18\2.3.18.csproj", "{07EF51F5-AA4C-42C2-91F2-FD8985CCA864}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.19", "2.3.19\2.3.19.csproj", "{C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.20", "2.3.20\2.3.20.csproj", "{ACB6B05B-F262-4950-A5E1-6EAA48EE8238}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.21", "2.3.21\2.3.21.csproj", "{657EF2E4-1D20-475B-8B22-54A917A38210}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.22", "2.3.22\2.3.22.csproj", "{C51D70DF-E143-4541-93FA-3291863FA67D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.23", "2.3.23\2.3.23.csproj", "{DF288AE1-D508-4B83-A31C-F7C15769B7CA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.24", "2.3.24\2.3.24.csproj", "{E8871A11-D22E-4D50-BE68-470DD4671D8E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.25", "2.3.25\2.3.25.csproj", "{EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.26", "2.3.26\2.3.26.csproj", "{191F61AE-DBA5-4459-BDF3-09C188ECEDA8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.27", "2.3.27\2.3.27.csproj", "{D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.28", "2.3.28\2.3.28.csproj", "{BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.29", "2.3.29\2.3.29.csproj", "{74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.30", "2.3.30\2.3.30.csproj", "{DBAFF6E5-B894-4995-9C1F-5A6C830A933D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.31", "2.3.31\2.3.31.csproj", "{DE2E396C-E48B-4414-A12C-F4AD0E4587C2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Release|Any CPU.Build.0 = Release|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Release|Any CPU.Build.0 = Release|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Release|Any CPU.Build.0 = Release|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Release|Any CPU.Build.0 = Release|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Release|Any CPU.Build.0 = Release|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Release|Any CPU.Build.0 = Release|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Debug|Any CPU.Build.0 = Debug|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Release|Any CPU.ActiveCfg = Release|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Release|Any CPU.Build.0 = Release|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Release|Any CPU.Build.0 = Release|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Release|Any CPU.Build.0 = Release|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Release|Any CPU.ActiveCfg = Release|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Release|Any CPU.Build.0 = Release|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Release|Any CPU.Build.0 = Release|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Release|Any CPU.Build.0 = Release|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Release|Any CPU.Build.0 = Release|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Release|Any CPU.Build.0 = Release|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Release|Any CPU.Build.0 = Release|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Release|Any CPU.Build.0 = Release|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Debug|Any CPU.Build.0 = Debug|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Release|Any CPU.ActiveCfg = Release|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Release|Any CPU.Build.0 = Release|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Release|Any CPU.Build.0 = Release|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Release|Any CPU.Build.0 = Release|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Release|Any CPU.Build.0 = Release|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Release|Any CPU.Build.0 = Release|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Debug|Any CPU.Build.0 = Debug|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Release|Any CPU.ActiveCfg = Release|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Release|Any CPU.Build.0 = Release|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Release|Any CPU.Build.0 = Release|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Release|Any CPU.Build.0 = Release|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Release|Any CPU.Build.0 = Release|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Release|Any CPU.Build.0 = Release|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Release|Any CPU.Build.0 = Release|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Release|Any CPU.Build.0 = Release|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Release|Any CPU.Build.0 = Release|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Release|Any CPU.Build.0 = Release|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Release|Any CPU.Build.0 = Release|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {F5FB1710-8260-4D0B-A366-EFF40E64381F} = {E15F04CF-E19C-46F1-BDAC-26332BAEB27A} + {0B42B539-F300-4D97-B4D0-47249CCC6F01} = {70D79B29-6263-4137-A094-75EDE650959B} + {C713169E-361B-4DF3-BCCA-68740199FF52} = {70D79B29-6263-4137-A094-75EDE650959B} + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4} = {70D79B29-6263-4137-A094-75EDE650959B} + {387D908B-19C8-4CF8-828D-D244C85872B3} = {70D79B29-6263-4137-A094-75EDE650959B} + {324869E0-1699-46CA-BF4E-E99954BE4B98} = {70D79B29-6263-4137-A094-75EDE650959B} + {601FC4EB-6B24-4EF5-835D-9940A8EC6621} = {70D79B29-6263-4137-A094-75EDE650959B} + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9} = {70D79B29-6263-4137-A094-75EDE650959B} + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4} = {70D79B29-6263-4137-A094-75EDE650959B} + {49630892-92E5-42A0-A76B-5A84BFACBB59} = {70D79B29-6263-4137-A094-75EDE650959B} + {A084203F-4C71-4A74-9D8B-F76EFD052845} = {70D79B29-6263-4137-A094-75EDE650959B} + {14D53C1D-F1DF-4826-9063-A087C55B289B} = {70D79B29-6263-4137-A094-75EDE650959B} + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3} = {70D79B29-6263-4137-A094-75EDE650959B} + {EE14928B-180C-41DE-B6DE-F645F919C152} = {70D79B29-6263-4137-A094-75EDE650959B} + {8C16556D-9644-47C3-B88F-648C53FF0701} = {70D79B29-6263-4137-A094-75EDE650959B} + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6} = {7FC73184-7437-434A-9339-C190965ADC9D} + {691244C9-0DE3-4DB8-B11E-BCA70985C883} = {7FC73184-7437-434A-9339-C190965ADC9D} + {A5BAAA13-8458-43F8-B7A3-7E37F074832B} = {7FC73184-7437-434A-9339-C190965ADC9D} + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864} = {7FC73184-7437-434A-9339-C190965ADC9D} + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72} = {7FC73184-7437-434A-9339-C190965ADC9D} + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238} = {7FC73184-7437-434A-9339-C190965ADC9D} + {657EF2E4-1D20-475B-8B22-54A917A38210} = {7FC73184-7437-434A-9339-C190965ADC9D} + {C51D70DF-E143-4541-93FA-3291863FA67D} = {7FC73184-7437-434A-9339-C190965ADC9D} + {DF288AE1-D508-4B83-A31C-F7C15769B7CA} = {7FC73184-7437-434A-9339-C190965ADC9D} + {E8871A11-D22E-4D50-BE68-470DD4671D8E} = {7FC73184-7437-434A-9339-C190965ADC9D} + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1} = {2D8A0264-3D6B-4523-94BE-1E396CDB077C} + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8} = {2D8A0264-3D6B-4523-94BE-1E396CDB077C} + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA} = {2D8A0264-3D6B-4523-94BE-1E396CDB077C} + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44} = {2D8A0264-3D6B-4523-94BE-1E396CDB077C} + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95} = {2D8A0264-3D6B-4523-94BE-1E396CDB077C} + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D} = {2D8A0264-3D6B-4523-94BE-1E396CDB077C} + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2} = {2D8A0264-3D6B-4523-94BE-1E396CDB077C} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {29E25F11-448B-4B17-AB6A-44A24B4A3ED4} + EndGlobalSection +EndGlobal diff --git a/2 Sorting/2.3/Quick/BaseSort.cs b/2 Sorting/2.3/Quick/BaseSort.cs new file mode 100644 index 000000000..76dffc1c2 --- /dev/null +++ b/2 Sorting/2.3/Quick/BaseSort.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; + +namespace Quick +{ + /// + /// 排序算法类模板。 + /// + public abstract class BaseSort + { + /// + /// 对数组 a 进行排序,用各种不同的方式进行实现。 + /// + /// 用于排序的类型。 + /// 需要排序的数组。 + public abstract void Sort(T[] a) where T : IComparable; + + /// + /// 比较第一个参数是否小于第二个参数。 + /// + /// 第一个参数。 + /// 第二个参数。 + /// 如果第一个参数小于第二个参数则返回 true, + /// 否则返回 false。 + protected bool Less(T v, T w) where T : IComparable + { + return v.CompareTo(w) < 0; + } + + /// + /// 使用指定的比较器比较第一个参数是否小于第二个参数。 + /// + /// 比较的元素类型。 + /// 比较的第一个元素。 + /// 比较的第二个元素 + /// 比较器。 + /// + protected bool Less(T v, T w, IComparer c) + { + return c.Compare(v, w) < 0; + } + + /// + /// 交换数组中下标为 i, j 的两个元素。 + /// + /// 元素的类型。 + /// 元素所在的数组。 + /// 需要交换的第一个元素。 + /// 需要交换的第二个元素。 + protected void Exch(T[] a, int i, int j) + { + T t = a[i]; + a[i] = a[j]; + a[j] = t; + } + + /// + /// 将数组的内容打印在一行中。 + /// + /// 需要打印的数组。 + protected void Show(T[] a) where T : IComparable + { + for (int i = 0; i < a.Length; i++) + { + Console.Write(a[i] + " "); + } + Console.WriteLine(); + } + + /// + /// 检查数组是否有序(升序)。 + /// + /// 需要检查的数组。 + /// 有序则返回 true,否则返回 false。 + public bool IsSorted(T[] a) where T : IComparable + { + for (int i = 1; i < a.Length; i++) + { + if (Less(a[i], a[i - 1])) + return false; + } + return true; + } + + /// + /// 检查数组是否有序。(使用指定的比较器) + /// + /// 需要检查的数组。 + /// 比较器。 + /// 有序则返回 true,否则返回 false。 + public bool IsSorted(T[] a, IComparer c) + { + for (int i = 1; i < a.Length; i++) + { + if (Less(a[i], a[i - 1], c)) + return false; + } + return true; + } + + /// + /// 检查数组在范围 [lo, hi] 内是否有序(升序)。 + /// + /// 需要检查的数组。 + /// 检查范围的下界。 + /// 检查范围的上界。 + /// 有序则返回 true,否则返回 false。 + public bool IsSorted(T[] a, int lo, int hi) where T : IComparable + { + for (int i = lo + 1; i <= hi; i++) + { + if (Less(a[i], a[i - 1])) + return false; + } + return true; + } + + /// + /// 检查数组在指定范围内是否有序。(使用指定的比较器) + /// + /// 数组的元素类型。 + /// 需要检查的数组。 + /// 检查范围的下界。 + /// 检查范围的上界。 + /// 比较器。 + /// 有序则返回 true,否则返回 false。 + public bool IsSorted(T[] a, int lo, int hi, IComparer c) + { + for (int i = lo + 1; i <= hi; i++) + { + if (Less(a[i], a[i - 1], c)) + return false; + } + return true; + } + } +} diff --git a/2 Sorting/2.3/Quick/Properties/AssemblyInfo.cs b/2 Sorting/2.3/Quick/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..9821f6a4c --- /dev/null +++ b/2 Sorting/2.3/Quick/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Quick")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Quick")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("f5fb1710-8260-4d0b-a366-eff40e64381f")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/2 Sorting/2.3/Quick/Quick.csproj b/2 Sorting/2.3/Quick/Quick.csproj new file mode 100644 index 000000000..6a9d4574b --- /dev/null +++ b/2 Sorting/2.3/Quick/Quick.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F} + Library + Properties + Quick + Quick + v4.7 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2 Sorting/2.3/Quick/Quick3Way.cs b/2 Sorting/2.3/Quick/Quick3Way.cs new file mode 100644 index 000000000..6570efe0a --- /dev/null +++ b/2 Sorting/2.3/Quick/Quick3Way.cs @@ -0,0 +1,75 @@ +using System; +using System.Diagnostics; + +namespace Quick +{ + /// + /// 三向切分的快速排序。 + /// + public class Quick3Way : BaseSort + { + /// + /// 默认构造函数。 + /// + public Quick3Way() { } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + private void Sort(T[] a, int lo, int hi) where T : IComparable + { + if (hi <= lo) // 别越界 + return; + + // 三向切分 + int lt = lo, i = lo + 1, gt = hi; + T v = a[lo]; + while (i <= gt) + { + int cmp = a[i].CompareTo(v); + if (cmp < 0) + Exch(a, lt++, i++); + else if (cmp > 0) + Exch(a, i, gt--); + else + i++; + } + + Sort(a, lo, lt - 1); + Sort(a, gt + 1, hi); + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/Quick/QuickBentleyMcIlroy.cs b/2 Sorting/2.3/Quick/QuickBentleyMcIlroy.cs new file mode 100644 index 000000000..2f3d6d3d9 --- /dev/null +++ b/2 Sorting/2.3/Quick/QuickBentleyMcIlroy.cs @@ -0,0 +1,148 @@ +using System; +using System.Diagnostics; + +namespace Quick +{ + public class QuickBentleyMcIlroy : BaseSort + { + /// + /// 小于这个数值的数组调用插入排序。 + /// + private readonly int INSERTION_SORT_CUTOFF = 8; + + /// + /// 小于这个数值的数组调用中位数作为枢轴。 + /// + private readonly int MEDIAN_OF_3_CUTOFF = 40; + + /// + /// 默认构造函数。 + /// + public QuickBentleyMcIlroy() { } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 对指定范围内的数组进行排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + /// 排序的起始下标。 + /// 排序的终止下标。 + private void Sort(T[] a, int lo, int hi) where T : IComparable + { + int n = hi - lo + 1; + + if (n <= this.INSERTION_SORT_CUTOFF) + { + InsertionSort(a, lo, hi); + return; + } + else if (n <= this.MEDIAN_OF_3_CUTOFF) + { + // 对于较小的数组,直接选择左中右三个元素中的中位数作为枢轴。 + int m = Median3(a, lo, lo + n / 2, hi); + Exch(a, m, lo); + } + else + { + // 对于较大的数组使用 Turkey Ninther 作为枢轴。 + int eps = n / 8; + int mid = lo + n / 2; + int m1 = Median3(a, lo, lo + eps, lo + eps + eps); + int m2 = Median3(a, mid - eps, mid, mid + eps); + int m3 = Median3(a, hi - eps - eps, hi - eps, hi); + int ninther = Median3(a, m1, m2, m3); + Exch(a, ninther, lo); + } + + // 三向切分 + int i = lo, j = hi + 1; + int p = lo, q = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) ; + while (Less(v, a[--j])) + if (j == lo) + break; + + if (i == j && IsEqual(a[i], v)) + Exch(a, ++p, i); + if (i >= j) + break; + + Exch(a, i, j); + if (IsEqual(a[i], v)) + Exch(a, ++p, i); + if (IsEqual(a[j], v)) + Exch(a, --q, j); + } + + i = j + 1; + for (int k = lo; k <= p; k++) + Exch(a, k, j--); + for (int k = hi; k >= q; k--) + Exch(a, k, i++); + + Sort(a, lo, j); + Sort(a, i, hi); + } + + /// + /// 判断两个元素是否值相等。 + /// + /// 需要判断的元素类型。 + /// 进行比较的第一个元素。 + /// 进行比较的第二个元素。 + /// 两个元素的值是否相等。 + private bool IsEqual(T a, T b) where T : IComparable + { + return a.CompareTo(b) == 0; + } + + /// + /// 用插入排序对指定范围内的数组排序。 + /// + /// 数组的元素类型。 + /// 需要排序的数组。 + /// 排序的起始下标。 + /// 排序的终止下标。 + private void InsertionSort(T[] a, int lo, int hi) where T : IComparable + { + for (int i = lo; i <= hi; i++) + { + for (int j = i; j > lo && Less(a[j], a[j - 1]); j--) + { + Exch(a, j, j - 1); + } + } + } + + /// + /// 获取三个元素中的中位数。 + /// + /// 用于排序的元素。 + /// 需要排序的数组。 + /// 第一个待选元素的下标。 + /// 第二个待选元素的下标。 + /// 第三个待选元素的下标。 + /// + private int Median3(T[] a, int i, int j, int k) where T : IComparable + { + return + (Less(a[i], a[j]) ? + (Less(a[j], a[k]) ? j : Less(a[i], a[k]) ? k : i) : + (Less(a[k], a[j]) ? j : Less(a[k], a[i]) ? k : i)); + } + } +} diff --git a/2 Sorting/2.3/Quick/QuickBest.cs b/2 Sorting/2.3/Quick/QuickBest.cs new file mode 100644 index 000000000..d7f3b8351 --- /dev/null +++ b/2 Sorting/2.3/Quick/QuickBest.cs @@ -0,0 +1,59 @@ +namespace Quick +{ + /// + /// 构建快速排序最佳情况的类。 + /// + public class QuickBest + { + /// + /// 构造函数,这个类不应该被实例化。 + /// + private QuickBest() { } + + /// + /// 构造适用于快速排序的最佳数组。 + /// + /// 数组长度。 + /// + public static int[] Best(int n) + { + int[] a = new int[n]; + for (int i = 0; i < n; i++) + { + a[i] = i; + } + Best(a, 0, n - 1); + return a; + } + + /// + /// 递归的构造数组。 + /// + /// 需要构造的数组。 + /// 构造的起始下标。 + /// 构造的终止下标。 + private static void Best(int[] a, int lo, int hi) + { + if (hi <= lo) + return; + int mid = lo + (hi - lo) / 2; + Best(a, lo, mid - 1); + Best(a, mid + 1, hi); + Exch(a, lo, mid); + } + + /// + /// 交换数组中的两个元素。 + /// + /// 数组的元素类型。 + /// 包含要交换元素的数组。 + /// 需要交换的第一个元素下标。 + /// 需要交换的第二个元素下标。 + private static void Exch(int[] a, int x, int y) + { + int t = a[x]; + a[x] = a[y]; + a[y] = t; + } + } +} diff --git a/2 Sorting/2.3/Quick/QuickSort.cs b/2 Sorting/2.3/Quick/QuickSort.cs new file mode 100644 index 000000000..8a0405844 --- /dev/null +++ b/2 Sorting/2.3/Quick/QuickSort.cs @@ -0,0 +1,89 @@ +using System; +using System.Diagnostics; + +namespace Quick +{ + /// + /// 快速排序类。 + /// + public class QuickSort : BaseSort + { + /// + /// 默认构造函数。 + /// + public QuickSort() { } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + Shuffle(a); + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + protected void Sort(T[] a, int lo, int hi) where T: IComparable + { + if (hi <= lo) // 别越界 + return; + int j = Partition(a, lo, hi); + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/Quick/QuickSortAnalyze.cs b/2 Sorting/2.3/Quick/QuickSortAnalyze.cs new file mode 100644 index 000000000..adc20a433 --- /dev/null +++ b/2 Sorting/2.3/Quick/QuickSortAnalyze.cs @@ -0,0 +1,168 @@ +using System; +using System.Diagnostics; + +namespace Quick +{ + /// + /// 自动记录比较次数以及子数组数量的快速排序类。 + /// + public class QuickSortAnalyze : BaseSort + { + /// + /// 比较次数。 + /// + public int CompareCount { get; set; } + + /// + /// 是否启用打乱。 + /// + public bool NeedShuffle { get; set; } + + /// + /// 是否显示轨迹。 + /// + public bool NeedPath { get; set; } + + /// + /// 大小为 0 的子数组数量。 + /// + public int Array0Num { get; set; } + + /// + /// 大小为 1 的子数组数量。 + /// + public int Array1Num { get; set; } + + /// + /// 大小为 2 的子数组数量。 + /// + public int Array2Num { get; set; } + + /// + /// 默认构造函数。 + /// + public QuickSortAnalyze() + { + this.CompareCount = 0; + this.NeedShuffle = true; + this.NeedPath = false; + this.Array0Num = 0; + this.Array1Num = 0; + this.Array2Num = 0; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + this.Array0Num = 0; + this.Array1Num = 0; + this.Array2Num = 0; + this.CompareCount = 0; + if (this.NeedShuffle) + Shuffle(a); + if (this.NeedPath) + { + for (int i = 0; i < a.Length; i++) + { + Console.Write(" "); + } + Console.WriteLine("\tlo\tj\thi"); + } + Sort(a, 0, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + private void Sort(T[] a, int lo, int hi) where T : IComparable + { + if (hi - lo == 1) + this.Array2Num++; + else if (hi == lo) + this.Array1Num++; + else if (hi < lo) + this.Array0Num++; + + if (hi <= lo) // 别越界 + return; + int j = Partition(a, lo, hi); + if (this.NeedPath) + { + for (int i = 0; i < a.Length; i++) + { + Console.Write(a[i] + " "); + } + Console.WriteLine("\t" + lo + "\t" + j + "\t" + hi); + } + Sort(a, lo, j - 1); + Sort(a, j + 1, hi); + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + + /// + /// 比较第一个元素是否小于第二个元素。 + /// + /// 要比较的元素类型。 + /// 第一个元素。 + /// 第二个元素。 + /// + new protected bool Less(T a, T b) where T : IComparable + { + this.CompareCount++; + return a.CompareTo(b) < 0; + } + } +} diff --git a/2 Sorting/2.3/Quick/SampleSort.cs b/2 Sorting/2.3/Quick/SampleSort.cs new file mode 100644 index 000000000..35b25d6e1 --- /dev/null +++ b/2 Sorting/2.3/Quick/SampleSort.cs @@ -0,0 +1,150 @@ +using System; +using System.Diagnostics; + +namespace Quick +{ + /// + /// 取样排序类。 + /// + public class SampleSort : QuickSort + { + /// + /// 取样数组长度 2^k - 1 的阶数。 + /// + public int K { get; set; } + + /// + /// 默认构造函数。 + /// + public SampleSort() + { + this.K = 8; + } + + /// + /// 用快速排序对数组 a 进行升序排序。 + /// + /// 需要排序的类型。 + /// 需要排序的数组。 + public override void Sort(T[] a) + { + if (a.Length < Math.Pow(2, this.K + 1)) + { + // 小于 2^(k+1) 的数组直接进行快排 + base.Sort(a); + return; + } + + Shuffle(a); + int samplehi = (int)Math.Pow(2, this.K) - 2; + // 利用快速排序对取样数组进行排序 + base.Sort(a, 0, samplehi); + // 找到取样数组的中位数 + int sampleMedian = samplehi / 2; + // 将取样数组后半部分放到数组末尾 + int i = samplehi, j = a.Length - 1; + while (i != sampleMedian) + Exch(a, i--, j--); + // 根据取样数组进行排序 + Sort(a, 0, sampleMedian, j, a.Length - 1); + Debug.Assert(IsSorted(a)); + } + + /// + /// 用快速排序对数组 a 的 lo ~ hi 范围排序。 + /// + /// 需要排序的数组类型。 + /// 需要排序的数组。 + /// 取样数组的起始下标。 + /// 排序范围的起始下标。 + /// 排序范围的结束下标。 + /// 取样数组的终止下标。 + private void Sort(T[] a, int samplelo, int lo, int hi, int samplehi) where T : IComparable + { + if (hi <= lo) // 别越界 + return; + + int j = Partition(a, lo, hi); + // 将前部的有序取样数组取半,后半部分放在枢轴前面。 + if (lo - samplelo > 1) + { + // p 应该始终指向有序部分的最后一项 + // v 应该始终指向有序部分的前面一项 + int p = lo - 1, v = j - 1; + for (int i = 0; i < (lo - samplelo) / 2; i++) + { + Exch(a, p--, v--); + } + Sort(a, samplelo, p, v, j - 1); + } + else + { + // 取样数组已经用完,退化为普通 Quicksort + base.Sort(a, samplelo, j - 1); + } + + // 将尾部有序取样数组取半,前半部分放在枢轴后面。 + if (samplehi - hi > 1) + { + // p 应该始终指向有序部分的前面一项 + // v 应该始终指向有序部分的最后一项 + int p = hi, v = j; + for (int i = 0; i < (samplehi - hi) / 2; i++) + { + Exch(a, ++p, ++v); + } + Sort(a, j + 1, v, p, samplehi); + } + else + { + // 取样数组已用完,退化为普通 Quicksort + base.Sort(a, j + 1, samplehi); + } + } + + /// + /// 对数组进行切分,返回枢轴位置。 + /// + /// 需要切分的数组类型。 + /// 需要切分的数组。 + /// 切分的起始点。 + /// 切分的末尾点。 + /// 枢轴下标。 + private int Partition(T[] a, int lo, int hi) where T : IComparable + { + int i = lo, j = hi + 1; + T v = a[lo]; + while (true) + { + while (Less(a[++i], v)) + if (i == hi) + break; + while (Less(v, a[--j])) + if (j == lo) + break; + if (i >= j) + break; + Exch(a, i, j); + } + Exch(a, lo, j); + return j; + } + + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + private void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + } +} diff --git a/2 Sorting/2.3/Quick/Sort2Distinct.cs b/2 Sorting/2.3/Quick/Sort2Distinct.cs new file mode 100644 index 000000000..3eb493ee3 --- /dev/null +++ b/2 Sorting/2.3/Quick/Sort2Distinct.cs @@ -0,0 +1,34 @@ +namespace Quick +{ + /// + /// 用于将只有两种元素的数组排序。 + /// + public class Sort2Distinct : BaseSort + { + /// + /// 默认构造函数。 + /// + public Sort2Distinct() { } + + /// + /// 对数组 a 进行排序。 + /// + /// 数组 a 的元素类型。 + /// + public override void Sort(T[] a) + { + int lt = 0, gt = a.Length - 1; + int i = 0; + while (i <= gt) + { + int cmp = a[i].CompareTo(a[lt]); + if (cmp < 0) + Exch(a, lt++, i++); + else if (cmp > 0) + Exch(a, i, gt--); + else + i++; + } + } + } +} diff --git a/2 Sorting/2.3/Quick/SortCompare.cs b/2 Sorting/2.3/Quick/SortCompare.cs new file mode 100644 index 000000000..8b311c883 --- /dev/null +++ b/2 Sorting/2.3/Quick/SortCompare.cs @@ -0,0 +1,181 @@ +using System; +using System.Diagnostics; + +namespace Quick +{ + /// + /// 静态类,提供一系列用于测试排序算法的方法。 + /// + public static class SortCompare + { + /// + /// 打乱数组。 + /// + /// 需要打乱的数组类型。 + /// 需要打乱的数组。 + public static void Shuffle(T[] a) + { + Random random = new Random(); + for (int i = 0; i < a.Length; i++) + { + int r = i + random.Next(a.Length - i); + T temp = a[i]; + a[i] = a[r]; + a[r] = temp; + } + } + + /// + /// 对相应排序算法执行一次耗时测试。 + /// + /// 用于测试的排序算法。 + /// 用于测试的数据。 + /// 排序的耗时。 + public static double Time(BaseSort sort, T[] a) where T : IComparable + { + Stopwatch stopwatch = Stopwatch.StartNew(); + sort.Sort(a); + return stopwatch.ElapsedMilliseconds; + } + + /// + /// 对相应排序算法做多次随机数据测试,返回总耗时。 + /// + /// 用于测试的排序算法。 + /// 每次测试的数据量。 + /// 测试次数。 + /// 多次排序的总耗时。 + public static double TimeRandomInput(BaseSort sort, int n, int trials) + { + double total = 0.0; + double[] a = new double[n]; + Random random = new Random(); + for (int t = 0; t < trials; t++) + { + for (int i = 0; i < n; i++) + { + a[i] = random.NextDouble(); + } + total += Time(sort, a); + } + return total; + } + + /// + /// 对相应排序算法做多次有序数据测试,返回总耗时。 + /// + /// 用于测试的排序算法。 + /// 每次测试的数据量。 + /// 测试次数。 + /// 多次排序的总耗时。 + public static double TimeSortedInput(BaseSort sort, int n, int trials) + { + double total = 0.0; + double[] a = new double[n]; + for (int t = 0; t < trials; t++) + { + for (int i = 0; i < n; i++) + { + a[i] = i * 1.0; + } + total += Time(sort, a); + } + return total; + } + + /// + /// 获取大小为 n 的随机整数数组。 + /// + /// 数组的大小。 + /// 大小为 n 的随机整数数组。 + public static int[] GetRandomArrayInt(int n) + { + Random random = new Random(); + int[] array = new int[n]; + for (int i = 0; i < n; i++) + { + array[i] = random.Next(); + } + return array; + } + + /// + /// 获取大小为 n 的随机 double 数组。 + /// + /// 随机数组的大小。 + /// 大小为 n 的随机 double 数组。 + public static double[] GetRandomArrayDouble(int n) + { + Random random = new Random(); + double[] array = new double[n]; + for (int i = 0; i < n; i++) + { + array[i] = random.NextDouble() * double.MaxValue; + } + return array; + } + + /// + /// 获取符合标准正态分布的 double 数组。 + /// + /// 数组大小。 + /// 符合标准正态分布的 double 数组。 + public static double[] GetNormalDistributionArray(int n) + { + double[] array = new double[n]; + for (int i = 0; i < n; i++) + { + array[i] = SortUtil.Normal(0, 1); + } + return array; + } + + /// + /// 产生符合泊松分布的随机数组。 + /// + /// 随机数组的大小。 + /// 符合泊松分布的数组。 + public static double[] GetPossionDistributionArray(int n) + { + double[] array = new double[n]; + for (int i = 0; i < n; i++) + { + array[i] = SortUtil.Poission(20); + } + return array; + } + + + /// + /// 产生符合几何分布的随机数组。 + /// + /// 随机数组的大小。 + /// 几何分布的概率。 + /// 符合几何分布的随机数组。 + public static double[] GetGeometricDistributionArray(int n, double p) + { + double[] array = new double[n]; + for (int i = 0; i < n; i++) + { + array[i] = SortUtil.Geometry(p); + } + return array; + } + + /// + /// 产生符合指定概率的离散分布的随机数组。 + /// + /// 随机数组的大小。 + /// 各取值的概率数组。 + /// 符合指定概率的离散分布的随机数组。 + public static double[] GetDiscretDistributionArray(int n, double[] probabilities) + { + double[] array = new double[n]; + for (int i = 0; i < n; i++) + { + array[i] = SortUtil.Discrete(probabilities); + } + return array; + } + } +} diff --git a/2 Sorting/2.3/Quick/SortUtil.cs b/2 Sorting/2.3/Quick/SortUtil.cs new file mode 100644 index 000000000..418626672 --- /dev/null +++ b/2 Sorting/2.3/Quick/SortUtil.cs @@ -0,0 +1,115 @@ +using System; + +namespace Quick +{ + /// + /// 静态类,包含用于生成排序算法测试数据的方法。 + /// + public static class SortUtil + { + + /// + /// 随机数发生器,所有对象共享同一个随机数发生器。 + /// + public static Random UniformGenerator = new Random(); + + /// + /// 产生符合正态分布的随机数。 + /// + /// 正态分布的期望值 μ。 + /// 正态分布的标准差 σ。 + /// 符合正态分布的随机数。 + public static double Normal(double average, double standardDeviation) + { + double u1 = UniformGenerator.NextDouble(); + double u2 = UniformGenerator.NextDouble(); + + double z0 = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Cos(Math.PI * 2 * u2); + + return z0 * standardDeviation + average; + } + + /// + /// 生成符合泊松分布的随机数。 + /// + /// 泊松分布的期望值 λ。 + /// 一个符合泊松分布的随机数。 + public static double Poission(double average) + { + double x = 0; + double p = Math.Pow(Math.E, -average); + double s = p; + double u = UniformGenerator.NextDouble(); + do + { + x++; + p *= average / x; + s += p; + } while (u > s); + return x; + } + + /// + /// 生成符合几何分布的随机数。 + /// + /// 几何分布的概率 p,这应该是一个小于 1 的非负数。 + /// 概率不能大于 1. + /// 符合几何分布的随机数。 + public static double Geometry(double p) + { + if (p > 1) + { + throw new ArgumentOutOfRangeException("p", "概率不能大于 1"); + } + + double result; + result = Math.Ceiling(Math.Log(1 - UniformGenerator.NextDouble()) / Math.Log(1 - p)); + + return result; + } + + /// + /// 根据指定的几率数组产生符合离散分布的随机数。 + /// + /// 各取值的可能性。 + /// 符合随机分布的随机整数。 + public static double Discrete(double[] probabilities) + { + if (probabilities == null) + { + throw new ArgumentNullException("Argument array is null"); + } + + double EPSION = 1E-14; + double sum = 0; + for (int i = 0; i < probabilities.Length; i++) + { + if (probabilities[i] <= 0) + { + throw new ArgumentException("array entry " + i + " must be nonnegative:" + probabilities[i]); + } + + sum += probabilities[i]; + } + + if (sum > 1.0 + EPSION || sum < 1.0 - EPSION) + { + throw new ArgumentException("sum of array entries does not equal 1.0:" + sum); + } + + while (true) + { + double r = UniformGenerator.NextDouble(); + sum = 0.0; + for (int i = 0; i < probabilities.Length; i++) + { + sum += probabilities[i]; + if (sum > r) + { + return i; + } + } + } + } + } +} diff --git a/Algorithms 4th Edition.sln b/Algorithms 4th Edition.sln index cc4aaeea7..9e24a051a 100644 --- a/Algorithms 4th Edition.sln +++ b/Algorithms 4th Edition.sln @@ -620,6 +620,80 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.2.28", "2 Sorting\2.2\2.2 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.2.29", "2 Sorting\2.2\2.2.29\2.2.29.csproj", "{FFAB614C-0523-4FFF-82DF-56C2BFE138D0}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.3 快速排序", "2.3 快速排序", "{706433D9-CB7B-43F0-864F-A6CF055DF1A9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1-基础题(2.3.1~2.3.14)", "1-基础题(2.3.1~2.3.14)", "{0C611987-9A62-4B96-BD27-4AA3BFDFAD90}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2-提高题(2.3.15~2.3.24)", "2-提高题(2.3.15~2.3.24)", "{5BA969C3-82E7-4E82-BABF-20745FE1CE23}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3-实验题(2.3.25~2.3.31)", "3-实验题(2.3.25~2.3.31)", "{23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "0-类库", "0-类库", "{3891501E-B332-493F-87E5-C8C9DFB4D820}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quick", "2 Sorting\2.3\Quick\Quick.csproj", "{F5FB1710-8260-4D0B-A366-EFF40E64381F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.1", "2 Sorting\2.3\2.3.1\2.3.1.csproj", "{0B42B539-F300-4D97-B4D0-47249CCC6F01}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.2", "2 Sorting\2.3\2.3.2\2.3.2.csproj", "{C713169E-361B-4DF3-BCCA-68740199FF52}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.3", "2 Sorting\2.3\2.3.3\2.3.3.csproj", "{B4CB8167-E055-43EF-B61F-744F0A2BB7F4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.4", "2 Sorting\2.3\2.3.4\2.3.4.csproj", "{387D908B-19C8-4CF8-828D-D244C85872B3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.5", "2 Sorting\2.3\2.3.5\2.3.5.csproj", "{324869E0-1699-46CA-BF4E-E99954BE4B98}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.6", "2 Sorting\2.3\2.3.6\2.3.6.csproj", "{601FC4EB-6B24-4EF5-835D-9940A8EC6621}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.7", "2 Sorting\2.3\2.3.7\2.3.7.csproj", "{426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.8", "2 Sorting\2.3\2.3.8\2.3.8.csproj", "{69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.9", "2 Sorting\2.3\2.3.9\2.3.9.csproj", "{49630892-92E5-42A0-A76B-5A84BFACBB59}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.10", "2 Sorting\2.3\2.3.10\2.3.10.csproj", "{A084203F-4C71-4A74-9D8B-F76EFD052845}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.11", "2 Sorting\2.3\2.3.11\2.3.11.csproj", "{14D53C1D-F1DF-4826-9063-A087C55B289B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.12", "2 Sorting\2.3\2.3.12\2.3.12.csproj", "{4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.13", "2 Sorting\2.3\2.3.13\2.3.13.csproj", "{EE14928B-180C-41DE-B6DE-F645F919C152}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.14", "2 Sorting\2.3\2.3.14\2.3.14.csproj", "{8C16556D-9644-47C3-B88F-648C53FF0701}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.15", "2 Sorting\2.3\2.3.15\2.3.15.csproj", "{277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.16", "2 Sorting\2.3\2.3.16\2.3.16.csproj", "{691244C9-0DE3-4DB8-B11E-BCA70985C883}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.17", "2 Sorting\2.3\2.3.17\2.3.17.csproj", "{A5BAAA13-8458-43F8-B7A3-7E37F074832B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.18", "2 Sorting\2.3\2.3.18\2.3.18.csproj", "{07EF51F5-AA4C-42C2-91F2-FD8985CCA864}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.19", "2 Sorting\2.3\2.3.19\2.3.19.csproj", "{C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.20", "2 Sorting\2.3\2.3.20\2.3.20.csproj", "{ACB6B05B-F262-4950-A5E1-6EAA48EE8238}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.21", "2 Sorting\2.3\2.3.21\2.3.21.csproj", "{657EF2E4-1D20-475B-8B22-54A917A38210}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.22", "2 Sorting\2.3\2.3.22\2.3.22.csproj", "{C51D70DF-E143-4541-93FA-3291863FA67D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.23", "2 Sorting\2.3\2.3.23\2.3.23.csproj", "{DF288AE1-D508-4B83-A31C-F7C15769B7CA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.24", "2 Sorting\2.3\2.3.24\2.3.24.csproj", "{E8871A11-D22E-4D50-BE68-470DD4671D8E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.25", "2 Sorting\2.3\2.3.25\2.3.25.csproj", "{EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.26", "2 Sorting\2.3\2.3.26\2.3.26.csproj", "{191F61AE-DBA5-4459-BDF3-09C188ECEDA8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.27", "2 Sorting\2.3\2.3.27\2.3.27.csproj", "{D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.28", "2 Sorting\2.3\2.3.28\2.3.28.csproj", "{BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.29", "2 Sorting\2.3\2.3.29\2.3.29.csproj", "{74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.30", "2 Sorting\2.3\2.3.30\2.3.30.csproj", "{DBAFF6E5-B894-4995-9C1F-5A6C830A933D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2.3.31", "2 Sorting\2.3\2.3.31\2.3.31.csproj", "{DE2E396C-E48B-4414-A12C-F4AD0E4587C2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -3726,6 +3800,390 @@ Global {FFAB614C-0523-4FFF-82DF-56C2BFE138D0}.Release|x64.Build.0 = Release|Any CPU {FFAB614C-0523-4FFF-82DF-56C2BFE138D0}.Release|x86.ActiveCfg = Release|Any CPU {FFAB614C-0523-4FFF-82DF-56C2BFE138D0}.Release|x86.Build.0 = Release|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Debug|x64.ActiveCfg = Debug|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Debug|x64.Build.0 = Debug|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Debug|x86.ActiveCfg = Debug|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Debug|x86.Build.0 = Debug|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Release|Any CPU.Build.0 = Release|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Release|x64.ActiveCfg = Release|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Release|x64.Build.0 = Release|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Release|x86.ActiveCfg = Release|Any CPU + {F5FB1710-8260-4D0B-A366-EFF40E64381F}.Release|x86.Build.0 = Release|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Debug|x64.ActiveCfg = Debug|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Debug|x64.Build.0 = Debug|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Debug|x86.ActiveCfg = Debug|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Debug|x86.Build.0 = Debug|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Release|Any CPU.Build.0 = Release|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Release|x64.ActiveCfg = Release|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Release|x64.Build.0 = Release|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Release|x86.ActiveCfg = Release|Any CPU + {0B42B539-F300-4D97-B4D0-47249CCC6F01}.Release|x86.Build.0 = Release|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Debug|x64.ActiveCfg = Debug|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Debug|x64.Build.0 = Debug|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Debug|x86.ActiveCfg = Debug|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Debug|x86.Build.0 = Debug|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Release|Any CPU.Build.0 = Release|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Release|x64.ActiveCfg = Release|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Release|x64.Build.0 = Release|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Release|x86.ActiveCfg = Release|Any CPU + {C713169E-361B-4DF3-BCCA-68740199FF52}.Release|x86.Build.0 = Release|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Debug|x64.ActiveCfg = Debug|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Debug|x64.Build.0 = Debug|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Debug|x86.ActiveCfg = Debug|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Debug|x86.Build.0 = Debug|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Release|Any CPU.Build.0 = Release|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Release|x64.ActiveCfg = Release|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Release|x64.Build.0 = Release|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Release|x86.ActiveCfg = Release|Any CPU + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4}.Release|x86.Build.0 = Release|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Debug|x64.ActiveCfg = Debug|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Debug|x64.Build.0 = Debug|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Debug|x86.ActiveCfg = Debug|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Debug|x86.Build.0 = Debug|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Release|Any CPU.Build.0 = Release|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Release|x64.ActiveCfg = Release|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Release|x64.Build.0 = Release|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Release|x86.ActiveCfg = Release|Any CPU + {387D908B-19C8-4CF8-828D-D244C85872B3}.Release|x86.Build.0 = Release|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Debug|x64.ActiveCfg = Debug|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Debug|x64.Build.0 = Debug|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Debug|x86.ActiveCfg = Debug|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Debug|x86.Build.0 = Debug|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Release|Any CPU.Build.0 = Release|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Release|x64.ActiveCfg = Release|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Release|x64.Build.0 = Release|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Release|x86.ActiveCfg = Release|Any CPU + {324869E0-1699-46CA-BF4E-E99954BE4B98}.Release|x86.Build.0 = Release|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Debug|Any CPU.Build.0 = Debug|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Debug|x64.ActiveCfg = Debug|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Debug|x64.Build.0 = Debug|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Debug|x86.ActiveCfg = Debug|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Debug|x86.Build.0 = Debug|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Release|Any CPU.ActiveCfg = Release|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Release|Any CPU.Build.0 = Release|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Release|x64.ActiveCfg = Release|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Release|x64.Build.0 = Release|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Release|x86.ActiveCfg = Release|Any CPU + {601FC4EB-6B24-4EF5-835D-9940A8EC6621}.Release|x86.Build.0 = Release|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Debug|x64.ActiveCfg = Debug|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Debug|x64.Build.0 = Debug|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Debug|x86.ActiveCfg = Debug|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Debug|x86.Build.0 = Debug|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Release|Any CPU.Build.0 = Release|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Release|x64.ActiveCfg = Release|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Release|x64.Build.0 = Release|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Release|x86.ActiveCfg = Release|Any CPU + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9}.Release|x86.Build.0 = Release|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Debug|x64.ActiveCfg = Debug|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Debug|x64.Build.0 = Debug|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Debug|x86.ActiveCfg = Debug|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Debug|x86.Build.0 = Debug|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Release|Any CPU.Build.0 = Release|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Release|x64.ActiveCfg = Release|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Release|x64.Build.0 = Release|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Release|x86.ActiveCfg = Release|Any CPU + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4}.Release|x86.Build.0 = Release|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Debug|x64.ActiveCfg = Debug|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Debug|x64.Build.0 = Debug|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Debug|x86.ActiveCfg = Debug|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Debug|x86.Build.0 = Debug|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Release|Any CPU.ActiveCfg = Release|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Release|Any CPU.Build.0 = Release|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Release|x64.ActiveCfg = Release|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Release|x64.Build.0 = Release|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Release|x86.ActiveCfg = Release|Any CPU + {49630892-92E5-42A0-A76B-5A84BFACBB59}.Release|x86.Build.0 = Release|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Debug|x64.ActiveCfg = Debug|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Debug|x64.Build.0 = Debug|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Debug|x86.ActiveCfg = Debug|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Debug|x86.Build.0 = Debug|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Release|Any CPU.Build.0 = Release|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Release|x64.ActiveCfg = Release|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Release|x64.Build.0 = Release|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Release|x86.ActiveCfg = Release|Any CPU + {A084203F-4C71-4A74-9D8B-F76EFD052845}.Release|x86.Build.0 = Release|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Debug|x64.ActiveCfg = Debug|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Debug|x64.Build.0 = Debug|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Debug|x86.ActiveCfg = Debug|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Debug|x86.Build.0 = Debug|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Release|Any CPU.Build.0 = Release|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Release|x64.ActiveCfg = Release|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Release|x64.Build.0 = Release|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Release|x86.ActiveCfg = Release|Any CPU + {14D53C1D-F1DF-4826-9063-A087C55B289B}.Release|x86.Build.0 = Release|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Debug|x64.ActiveCfg = Debug|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Debug|x64.Build.0 = Debug|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Debug|x86.ActiveCfg = Debug|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Debug|x86.Build.0 = Debug|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Release|Any CPU.Build.0 = Release|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Release|x64.ActiveCfg = Release|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Release|x64.Build.0 = Release|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Release|x86.ActiveCfg = Release|Any CPU + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3}.Release|x86.Build.0 = Release|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Debug|x64.ActiveCfg = Debug|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Debug|x64.Build.0 = Debug|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Debug|x86.ActiveCfg = Debug|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Debug|x86.Build.0 = Debug|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Release|Any CPU.Build.0 = Release|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Release|x64.ActiveCfg = Release|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Release|x64.Build.0 = Release|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Release|x86.ActiveCfg = Release|Any CPU + {EE14928B-180C-41DE-B6DE-F645F919C152}.Release|x86.Build.0 = Release|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Debug|x64.ActiveCfg = Debug|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Debug|x64.Build.0 = Debug|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Debug|x86.ActiveCfg = Debug|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Debug|x86.Build.0 = Debug|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Release|Any CPU.Build.0 = Release|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Release|x64.ActiveCfg = Release|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Release|x64.Build.0 = Release|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Release|x86.ActiveCfg = Release|Any CPU + {8C16556D-9644-47C3-B88F-648C53FF0701}.Release|x86.Build.0 = Release|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Debug|x64.ActiveCfg = Debug|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Debug|x64.Build.0 = Debug|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Debug|x86.ActiveCfg = Debug|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Debug|x86.Build.0 = Debug|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Release|Any CPU.Build.0 = Release|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Release|x64.ActiveCfg = Release|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Release|x64.Build.0 = Release|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Release|x86.ActiveCfg = Release|Any CPU + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6}.Release|x86.Build.0 = Release|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Debug|Any CPU.Build.0 = Debug|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Debug|x64.ActiveCfg = Debug|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Debug|x64.Build.0 = Debug|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Debug|x86.ActiveCfg = Debug|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Debug|x86.Build.0 = Debug|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Release|Any CPU.ActiveCfg = Release|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Release|Any CPU.Build.0 = Release|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Release|x64.ActiveCfg = Release|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Release|x64.Build.0 = Release|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Release|x86.ActiveCfg = Release|Any CPU + {691244C9-0DE3-4DB8-B11E-BCA70985C883}.Release|x86.Build.0 = Release|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Debug|x64.ActiveCfg = Debug|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Debug|x64.Build.0 = Debug|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Debug|x86.ActiveCfg = Debug|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Debug|x86.Build.0 = Debug|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Release|Any CPU.Build.0 = Release|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Release|x64.ActiveCfg = Release|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Release|x64.Build.0 = Release|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Release|x86.ActiveCfg = Release|Any CPU + {A5BAAA13-8458-43F8-B7A3-7E37F074832B}.Release|x86.Build.0 = Release|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Debug|x64.ActiveCfg = Debug|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Debug|x64.Build.0 = Debug|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Debug|x86.ActiveCfg = Debug|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Debug|x86.Build.0 = Debug|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Release|Any CPU.Build.0 = Release|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Release|x64.ActiveCfg = Release|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Release|x64.Build.0 = Release|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Release|x86.ActiveCfg = Release|Any CPU + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864}.Release|x86.Build.0 = Release|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Debug|x64.ActiveCfg = Debug|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Debug|x64.Build.0 = Debug|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Debug|x86.ActiveCfg = Debug|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Debug|x86.Build.0 = Debug|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Release|Any CPU.Build.0 = Release|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Release|x64.ActiveCfg = Release|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Release|x64.Build.0 = Release|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Release|x86.ActiveCfg = Release|Any CPU + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72}.Release|x86.Build.0 = Release|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Debug|x64.ActiveCfg = Debug|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Debug|x64.Build.0 = Debug|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Debug|x86.ActiveCfg = Debug|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Debug|x86.Build.0 = Debug|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Release|Any CPU.Build.0 = Release|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Release|x64.ActiveCfg = Release|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Release|x64.Build.0 = Release|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Release|x86.ActiveCfg = Release|Any CPU + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238}.Release|x86.Build.0 = Release|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Debug|Any CPU.Build.0 = Debug|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Debug|x64.ActiveCfg = Debug|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Debug|x64.Build.0 = Debug|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Debug|x86.ActiveCfg = Debug|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Debug|x86.Build.0 = Debug|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Release|Any CPU.ActiveCfg = Release|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Release|Any CPU.Build.0 = Release|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Release|x64.ActiveCfg = Release|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Release|x64.Build.0 = Release|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Release|x86.ActiveCfg = Release|Any CPU + {657EF2E4-1D20-475B-8B22-54A917A38210}.Release|x86.Build.0 = Release|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Debug|x64.ActiveCfg = Debug|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Debug|x64.Build.0 = Debug|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Debug|x86.ActiveCfg = Debug|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Debug|x86.Build.0 = Debug|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Release|Any CPU.Build.0 = Release|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Release|x64.ActiveCfg = Release|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Release|x64.Build.0 = Release|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Release|x86.ActiveCfg = Release|Any CPU + {C51D70DF-E143-4541-93FA-3291863FA67D}.Release|x86.Build.0 = Release|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Debug|x64.ActiveCfg = Debug|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Debug|x64.Build.0 = Debug|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Debug|x86.ActiveCfg = Debug|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Debug|x86.Build.0 = Debug|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Release|Any CPU.Build.0 = Release|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Release|x64.ActiveCfg = Release|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Release|x64.Build.0 = Release|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Release|x86.ActiveCfg = Release|Any CPU + {DF288AE1-D508-4B83-A31C-F7C15769B7CA}.Release|x86.Build.0 = Release|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Debug|x64.ActiveCfg = Debug|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Debug|x64.Build.0 = Debug|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Debug|x86.ActiveCfg = Debug|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Debug|x86.Build.0 = Debug|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Release|Any CPU.Build.0 = Release|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Release|x64.ActiveCfg = Release|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Release|x64.Build.0 = Release|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Release|x86.ActiveCfg = Release|Any CPU + {E8871A11-D22E-4D50-BE68-470DD4671D8E}.Release|x86.Build.0 = Release|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Debug|x64.ActiveCfg = Debug|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Debug|x64.Build.0 = Debug|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Debug|x86.ActiveCfg = Debug|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Debug|x86.Build.0 = Debug|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Release|Any CPU.Build.0 = Release|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Release|x64.ActiveCfg = Release|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Release|x64.Build.0 = Release|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Release|x86.ActiveCfg = Release|Any CPU + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1}.Release|x86.Build.0 = Release|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Debug|x64.ActiveCfg = Debug|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Debug|x64.Build.0 = Debug|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Debug|x86.ActiveCfg = Debug|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Debug|x86.Build.0 = Debug|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Release|Any CPU.Build.0 = Release|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Release|x64.ActiveCfg = Release|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Release|x64.Build.0 = Release|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Release|x86.ActiveCfg = Release|Any CPU + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8}.Release|x86.Build.0 = Release|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Debug|x64.ActiveCfg = Debug|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Debug|x64.Build.0 = Debug|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Debug|x86.ActiveCfg = Debug|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Debug|x86.Build.0 = Debug|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Release|Any CPU.Build.0 = Release|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Release|x64.ActiveCfg = Release|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Release|x64.Build.0 = Release|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Release|x86.ActiveCfg = Release|Any CPU + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA}.Release|x86.Build.0 = Release|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Debug|x64.ActiveCfg = Debug|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Debug|x64.Build.0 = Debug|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Debug|x86.ActiveCfg = Debug|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Debug|x86.Build.0 = Debug|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Release|Any CPU.Build.0 = Release|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Release|x64.ActiveCfg = Release|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Release|x64.Build.0 = Release|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Release|x86.ActiveCfg = Release|Any CPU + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44}.Release|x86.Build.0 = Release|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Debug|x64.ActiveCfg = Debug|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Debug|x64.Build.0 = Debug|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Debug|x86.ActiveCfg = Debug|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Debug|x86.Build.0 = Debug|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Release|Any CPU.Build.0 = Release|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Release|x64.ActiveCfg = Release|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Release|x64.Build.0 = Release|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Release|x86.ActiveCfg = Release|Any CPU + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95}.Release|x86.Build.0 = Release|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Debug|x64.ActiveCfg = Debug|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Debug|x64.Build.0 = Debug|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Debug|x86.ActiveCfg = Debug|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Debug|x86.Build.0 = Debug|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Release|Any CPU.Build.0 = Release|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Release|x64.ActiveCfg = Release|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Release|x64.Build.0 = Release|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Release|x86.ActiveCfg = Release|Any CPU + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D}.Release|x86.Build.0 = Release|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Debug|x64.ActiveCfg = Debug|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Debug|x64.Build.0 = Debug|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Debug|x86.ActiveCfg = Debug|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Debug|x86.Build.0 = Debug|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Release|Any CPU.Build.0 = Release|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Release|x64.ActiveCfg = Release|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Release|x64.Build.0 = Release|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Release|x86.ActiveCfg = Release|Any CPU + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -4027,6 +4485,43 @@ Global {2F7A13F9-7F7B-49F9-A578-C9E6C402AFAD} = {A626CD59-137B-4896-8FC6-E0D42B4C3572} {F891FFE5-90E9-447D-98D7-C0A23ACE63D7} = {A626CD59-137B-4896-8FC6-E0D42B4C3572} {FFAB614C-0523-4FFF-82DF-56C2BFE138D0} = {A626CD59-137B-4896-8FC6-E0D42B4C3572} + {706433D9-CB7B-43F0-864F-A6CF055DF1A9} = {F875DDB4-FC47-4F8A-AE73-D22CE5BDB0D6} + {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} = {706433D9-CB7B-43F0-864F-A6CF055DF1A9} + {5BA969C3-82E7-4E82-BABF-20745FE1CE23} = {706433D9-CB7B-43F0-864F-A6CF055DF1A9} + {23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE} = {706433D9-CB7B-43F0-864F-A6CF055DF1A9} + {3891501E-B332-493F-87E5-C8C9DFB4D820} = {706433D9-CB7B-43F0-864F-A6CF055DF1A9} + {F5FB1710-8260-4D0B-A366-EFF40E64381F} = {3891501E-B332-493F-87E5-C8C9DFB4D820} + {0B42B539-F300-4D97-B4D0-47249CCC6F01} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {C713169E-361B-4DF3-BCCA-68740199FF52} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {B4CB8167-E055-43EF-B61F-744F0A2BB7F4} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {387D908B-19C8-4CF8-828D-D244C85872B3} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {324869E0-1699-46CA-BF4E-E99954BE4B98} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {601FC4EB-6B24-4EF5-835D-9940A8EC6621} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {426B6F5B-CF6F-4F06-88D7-DE5B658FD2C9} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {69CDEB12-6317-46C1-9DEF-F5946DDE9AD4} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {49630892-92E5-42A0-A76B-5A84BFACBB59} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {A084203F-4C71-4A74-9D8B-F76EFD052845} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {14D53C1D-F1DF-4826-9063-A087C55B289B} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {4B4D4355-6F8F-436B-A471-D33EAA7DA7A3} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {EE14928B-180C-41DE-B6DE-F645F919C152} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {8C16556D-9644-47C3-B88F-648C53FF0701} = {0C611987-9A62-4B96-BD27-4AA3BFDFAD90} + {277BF76B-D2B5-46A2-9623-BAA6AC38A4E6} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {691244C9-0DE3-4DB8-B11E-BCA70985C883} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {A5BAAA13-8458-43F8-B7A3-7E37F074832B} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {07EF51F5-AA4C-42C2-91F2-FD8985CCA864} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {C2FFAD8E-DA39-4F50-883F-C72FEBECDF72} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {ACB6B05B-F262-4950-A5E1-6EAA48EE8238} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {657EF2E4-1D20-475B-8B22-54A917A38210} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {C51D70DF-E143-4541-93FA-3291863FA67D} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {DF288AE1-D508-4B83-A31C-F7C15769B7CA} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {E8871A11-D22E-4D50-BE68-470DD4671D8E} = {5BA969C3-82E7-4E82-BABF-20745FE1CE23} + {EDD5937F-3098-4DE4-B1C7-6255BEF8F8F1} = {23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE} + {191F61AE-DBA5-4459-BDF3-09C188ECEDA8} = {23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE} + {D95B626C-A04B-4D61-A9B7-16B3EDFD2CEA} = {23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE} + {BA0FB027-2A8C-4421-BF8B-5E880CB4AA44} = {23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE} + {74D02CC1-D0E9-46ED-B6C2-5C6CAF0DDF95} = {23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE} + {DBAFF6E5-B894-4995-9C1F-5A6C830A933D} = {23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE} + {DE2E396C-E48B-4414-A12C-F4AD0E4587C2} = {23BC9AC8-E58E-4ACC-BFBB-93D2DB7483CE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {EE55CF8D-6F35-464D-B95B-ED85644AE41C} diff --git a/README.md b/README.md index ea2f66c76..6dd6739c5 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 算法(第4版)习题题解 C# 版 -当前已经完成到 2.2。 +当前已经完成到 2.3。 可以在这个网站搜索题解:https://ikesnowy.github.io/Alg4-Solutions/ @@ -10,27 +10,22 @@ - [1.基础 Fundamental](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/1%20Fundamental) - [1.1 基础编程模型 Programming Model](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/1%20Fundamental/1.1) - - [1.2 数据抽象 Data Abstraction](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/1%20Fundamental/1.2) - - [1.3 背包、队列和栈 Bags, Queues, and Stacks](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/1%20Fundamental/1.3) - - [1.4 算法分析 Analysis of Algorithms](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/1%20Fundamental/1.4) - - [1.5 案例研究:union-find 算法 CaseStudy: UnionFind](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/1%20Fundamental/1.5) - [2.排序 Sorting](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/2%20Sorting) - - [2.1 初级排序算法 Elementary Sorts](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/2%20Sorting/2.1) - - [2.2 归并排序 Mergesort](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/2%20Sorting/2.2) + - [2.3 快速排序 Quicksort](https://github.com/ikesnowy/Algorithms-4th-Edition-in-Csharp/tree/master/2%20Sorting/2.3) ## 使用方法 & 测试环境 ### 使用方法:   -1. 下载整个解决方案(可能会非常大),打开 Algorithms 4th Edition.sln 文件,右击需要的项目--设为启动项目,运行。   +1. 下载整个解决方案(可能会非常大),打开 Algorithms 4th Edition.sln 文件,右击需要的项目--设为启动项目,运行。 2. 下载对应章节文件夹(例如文件夹 1.3),打开包含在其中的解决方案(例如 1.3.sln)文件,右击需要的项目--设为启动项目,运行。 3. 下载你需要的项目文件和库文件(库文件一般位于相应章节文件夹下),添加到 Visual Studio 中运行。 例如,下载了 1.3.26 和 Generics 文件夹。打开 1.3.26 文件夹下的项目文件之后(后缀为 .csproj 的文件),Visual Studio 会自动生成一个解决方案。 @@ -61,7 +56,13 @@ CPU: i7 4650U @1.70GHz 第一章:Windows10 15063 + Visual Studio 2017 + .NET Framework 4.7 -第二章及以后:Windows10 16299 + Visual Studio 2017 + .NET Framework 4.7 +第二章: + +2.1 Windows10 16299 + Visual Studio 2017 + .NET Framework 4.7 + +2.2 Windows10 17134 + Visual Studio 2017 + .NET Framework 4.7 + +2.3 Windows10 17134 + Visual Studio 2017 + .NET Framework 4.7 ## 代码规范: @@ -134,7 +135,9 @@ CPU: i7 4650U @1.70GHz 官方 MOOC 课程: -https://www.coursera.org/learn/algorithms-part1 +Part1 https://www.coursera.org/learn/algorithms-part1 + +Part2 https://www.coursera.org/learn/algorithms-part2 官方资料站 (English):