1.概要
SortedSet<int> vs = new SortedSet<int>();
vs.Add(arrayInt[i]);
2.代码
using System;
using System.Collections.Generic;
namespace ConsoleApp11
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
SortedSet<int> vs = new SortedSet<int>();
int[] arrayInt = { 4, 5 };
Console.WriteLine("输入的顺序");
for (int i = 0; i < arrayInt.Length; i++) {
Console.WriteLine(arrayInt[i]);
vs.Add(arrayInt[i]);
}
Console.WriteLine("自动排序后");
foreach (int i in vs) {
Console.WriteLine(i);
}
Console.ReadKey();
}
}
}
3.运行结果

这篇博客展示了如何在C#中利用SortedSet数据结构对整数数组进行自动排序。通过创建一个SortedSet并逐个添加数组元素,然后遍历SortedSet,实现了输入数组的无序到自动排序的过程。
488

被折叠的 条评论
为什么被折叠?



