Skip to content

Commit 5aa9f08

Browse files
committed
3.2.44 Finished
1 parent 72baf22 commit 5aa9f08

File tree

9 files changed

+374
-1
lines changed

9 files changed

+374
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
<RootNamespace>_3._2._44</RootNamespace>
7+
<UseWindowsForms>true</UseWindowsForms>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\BinarySearchTree\BinarySearchTree.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Compile Update="Form1.cs">
16+
<SubType>Form</SubType>
17+
</Compile>
18+
<Compile Update="Form1.Designer.cs">
19+
<DependentUpon>Form1.cs</DependentUpon>
20+
</Compile>
21+
<Compile Update="Form2.cs">
22+
<SubType>Form</SubType>
23+
</Compile>
24+
<Compile Update="Form2.Designer.cs">
25+
<DependentUpon>Form2.cs</DependentUpon>
26+
</Compile>
27+
</ItemGroup>
28+
29+
</Project>

3 Searching/3.2/3.2.44/Form1.Designer.cs

Lines changed: 98 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3 Searching/3.2/3.2.44/Form1.cs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Windows.Forms;
3+
using BinarySearchTree;
4+
5+
namespace _3._2._44
6+
{
7+
public partial class Form1 : Form
8+
{
9+
public Form1()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
private void button1_Click(object sender, EventArgs e)
15+
{
16+
if (int.TryParse(textBox1.Text, out var n))
17+
{
18+
var result = Test(n);
19+
var drawPad = new Form2();
20+
drawPad.Show();
21+
drawPad.Draw(result);
22+
}
23+
else
24+
{
25+
label2.Text = @"请输入正确格式的数字!";
26+
}
27+
}
28+
29+
private long[] Test(int n)
30+
{
31+
var testCases = new long[n];
32+
var testResult = new long[n];
33+
for (var i = 0; i < n; i++)
34+
{
35+
testCases[i] = i;
36+
}
37+
Shuffle(testCases);
38+
39+
var bst = new BSTAnalysis<long, int>();
40+
for (var i = 0; i < n; i++)
41+
{
42+
bst.CompareTimes = 0;
43+
bst.Put(testCases[i], 1);
44+
testResult[i] = bst.CompareTimes;
45+
}
46+
47+
return testResult;
48+
}
49+
50+
static void Shuffle<T>(T[] a)
51+
{
52+
var random = new Random();
53+
for (var i = 0; i < a.Length; i++)
54+
{
55+
var r = i + random.Next(a.Length - i);
56+
var temp = a[i];
57+
a[i] = a[r];
58+
a[r] = temp;
59+
}
60+
}
61+
}
62+
}

3 Searching/3.2/3.2.44/Form2.Designer.cs

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

3 Searching/3.2/3.2.44/Form2.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Drawing;
2+
using System.Linq;
3+
using System.Windows.Forms;
4+
5+
namespace _3._2._44
6+
{
7+
public partial class Form2 : Form
8+
{
9+
public Form2()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
public void Draw(long[] data)
15+
{
16+
var panel = CreateGraphics();
17+
var unitX = (float)ClientRectangle.Width / data.Length;
18+
var unitY = (float)ClientRectangle.Height / data.Max();
19+
20+
var accumulation = 0f; // f = float
21+
for (var i = 0; i < data.Length; i++)
22+
{
23+
// Gray
24+
panel.FillEllipse(Brushes.Gray, (i + 1) * unitX, ClientRectangle.Bottom - data[i] * unitY, 2, 2);
25+
// Red
26+
panel.FillEllipse(Brushes.Red, (i + 1) * unitX, ClientRectangle.Bottom - accumulation / (i + 1) * unitY, 2, 2);
27+
accumulation += data[i];
28+
}
29+
30+
panel.DrawString($"n:{data.Length}\nave:{accumulation / data.Length}", SystemFonts.DefaultFont, Brushes.Red, 0, 0);
31+
}
32+
}
33+
}

3 Searching/3.2/3.2.44/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Windows.Forms;
3+
4+
namespace _3._2._44
5+
{
6+
static class Program
7+
{
8+
/// <summary>
9+
/// The main entry point for the application.
10+
/// </summary>
11+
[STAThread]
12+
static void Main()
13+
{
14+
Application.SetHighDpiMode(HighDpiMode.SystemAware);
15+
Application.EnableVisualStyles();
16+
Application.SetCompatibleTextRenderingDefault(false);
17+
Application.Run(new Form1());
18+
}
19+
}
20+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
4+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
5+
<security>
6+
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
7+
<!-- UAC 清单选项
8+
如果想要更改 Windows 用户帐户控制级别,请使用
9+
以下节点之一替换 requestedExecutionLevel 节点。n
10+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
11+
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
12+
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
13+
14+
指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
15+
如果你的应用程序需要此虚拟化来实现向后兼容性,则删除此
16+
元素。
17+
-->
18+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
19+
</requestedPrivileges>
20+
</security>
21+
</trustInfo>
22+
23+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
24+
<application>
25+
<!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
26+
Windows 版本的列表。取消评论适当的元素,
27+
Windows 将自动选择最兼容的环境。 -->
28+
29+
<!-- Windows Vista -->
30+
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
31+
32+
<!-- Windows 7 -->
33+
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
34+
35+
<!-- Windows 8 -->
36+
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
37+
38+
<!-- Windows 8.1 -->
39+
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
40+
41+
<!-- Windows 10 -->
42+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
43+
44+
</application>
45+
</compatibility>
46+
47+
<!-- 指示该应用程序可以感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
48+
自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
49+
选择加入。选择加入此设置的 Windows 窗体应用程序(目标设定为 .NET Framework 4.6 )还应
50+
在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。-->
51+
52+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
53+
<windowsSettings>
54+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
55+
</windowsSettings>
56+
</application>
57+
58+
59+
<!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
60+
<!--
61+
<dependency>
62+
<dependentAssembly>
63+
<assemblyIdentity
64+
type="win32"
65+
name="Microsoft.Windows.Common-Controls"
66+
version="6.0.0.0"
67+
processorArchitecture="*"
68+
publicKeyToken="6595b64144ccf1df"
69+
language="*"
70+
/>
71+
</dependentAssembly>
72+
</dependency>
73+
-->
74+
75+
</assembly>

3 Searching/3.2/BinarySearchTree/BSTAnalysis.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ protected virtual Node Put(Node x, TKey key, TValue value)
100100
if (x == null)
101101
return new Node(key, value, 1);
102102
var cmp = key.CompareTo(x.Key);
103+
CompareTimes++;
103104
if (cmp < 0)
104105
x.Left = Put(x.Left, key, value);
105106
else if (cmp > 0)

0 commit comments

Comments
 (0)