zms9110750.TreeCollection
1.1.1
dotnet add package zms9110750.TreeCollection --version 1.1.1
NuGet\Install-Package zms9110750.TreeCollection -Version 1.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="zms9110750.TreeCollection" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="zms9110750.TreeCollection" Version="1.1.1" />
<PackageReference Include="zms9110750.TreeCollection" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add zms9110750.TreeCollection --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: zms9110750.TreeCollection, 1.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package zms9110750.TreeCollection@1.1.1
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=zms9110750.TreeCollection&version=1.1.1
#tool nuget:?package=zms9110750.TreeCollection&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
TreeCollection 使用说明
基本树结构操作
创建树和添加节点
// 创建根节点
var root = new TreeNode<string>("根节点");
// 批量添加子节点
root.Add(["子节点1", "子节点2", "子节点3"]);
// 嵌套添加子节点
root[0].Add("子节点1.1", "子节点1.2"); // 通过索引访问
root["子节点2"].Add("子节点2.1"); // 通过值访问
节点操作
// 移动节点到新父节点
root.Add(root[0][1]); // 将"子节点1.2"移动到根下
// 删除节点
root.RemoveAt(1); // 删除第二个子节点
// 获取根节点和深度
var rootNode = root.Root; // 获取根节点
int depth = root.Depth; // 获取当前节点深度
切片操作
// 获取前两个子节点
var slice = root[..2];
// 遍历切片
foreach(var node in slice)
{
Console.WriteLine(node.Value);
}
字典树(Trie)操作
var trie = new Trie();
// 添加单词
trie.Add("apple");
trie.Add("application");
trie.Add("banana");
// 搜索前缀
foreach(var word in trie.Search("app"))
{
Console.WriteLine(word); // 输出 apple, application
}
// 复杂搜索示例
/*
a b匹配:
ac b
ac cb b
不匹配:
ab
ac cb
*/
高级树操作
可视化树结构
// 输出树形结构
Console.WriteLine(root.ToString());
/*
输出示例:
根节点
├─ 子节点1
│ ├─ 子节点1.1
│ └─ 子节点1.2
├─ 子节点2
│ └─ 子节点2.1
└─ 子节点3
*/
批量操作
// 批量删除节点
root.RemoveAll(node => node.Value.StartsWith("子节点"));
这个库提供了极其简单直观的API来处理各种树结构,支持批量操作、切片访问和直观的树形可视化输出。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- zms9110750.InterfaceImplAsExtensionGenerator (>= 0.1.1.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
扩展方法改为了使用新语法的extension块。