CDQueue 1.0.1
dotnet add package CDQueue --version 1.0.1
NuGet\Install-Package CDQueue -Version 1.0.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="CDQueue" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CDQueue" Version="1.0.1" />
<PackageReference Include="CDQueue" />
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 CDQueue --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CDQueue, 1.0.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 CDQueue@1.0.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=CDQueue&version=1.0.1
#tool nuget:?package=CDQueue&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CDQueue
优先级队列,包含添加数据堆化与删除数据堆化。
1.使用方法:
0.默认使用内置数据泛型数据类Item
- Item含有两个成员
- name与priority
- item.PrintInfo();显示当前item信息
1.创建一个优先级队列:
CDQueue<Item> cdQue = new CDQueue<Item>();
2数据入队并自动堆化
Item item1 = new Item() { name = "1", priority = 2 };
Item item2 = new Item() { name = "2", priority = 8 };
Item item3 = new Item() { name = "3", priority = 6 };
adQue.Enqueue(item1);
adQue.Enqueue(item2);
adQue.Enqueue(item3);
3.删除堆顶数据并自动完成堆化
Item item = adQue.Dequeue();
4.移除指定元素并完成自动完成堆化
adQue.RemoveAt(removeIndex);
5.自动化测试
using CDUtils;
using System;
using System.Collections.Generic;
// 优先级队列验证程序
namespace PriorityQueueExample
{
class CDQueueExample
{
static void Main(string[] args)
{
Console.WriteLine("测试优先级队列");
AutoTest();
}
// 自动化测试程序
static void AutoTest()
{
int count = 1000 * 1000;
while(count > 0)
{
count--;
LoopTest();
}
Console.WriteLine("Test Successful!");
Console.ReadKey();
}
static void LoopTest()
{
// 测试流程:
// 1.生成数据
// 2.入队
// 3.出队
Random rd = new Random();
int genCount = rd.Next(100, 9999);
List<Item> itemList = new List<Item>(genCount);
for(int i = 0; i < genCount; i++)
{
itemList.Add(new Item
{
name = $"item_{i}",
priority = rd.Next(0, 1000)
}); ;
}
// 入队
CDQueue<Item> adQue = new CDQueue<Item>();
for(int i = 0; i< itemList.Count; i++)
{
adQue.Enqueue(itemList[i]);
}
// 生成随机移除的数据
int rmvCount = rd.Next(1, 9999);
for(int i = 0; i < rmvCount; i++)
{
int index = rd.Next(0, adQue.Count);
int adIndex = adQue.IndexOf(itemList[index]);
if(adIndex >= 0)
{
adQue.RemoveAt(adIndex);
}
}
// 出队
List<Item> outList = new List<Item>();
while(adQue.Count > 0)
{
Item item = adQue.Dequeue();
outList.Add(item);
item.PrintInfo();
}
// 排序检测
for(int i = 0; i < outList.Count; i++)
{
if (i < outList.Count - 1)
{
if(outList[i].priority > outList[i + 1].priority)
{
// 优先级排序异常
Exception e = new Exception("优先级顺序异常");
throw e;
}
}
}
}
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.