using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class 哈希set : MonoBehaviour {
//包含不重复项的无序列表
HashSet<int> hs1 = new HashSet<int>();
HashSet<int> hs2 = new HashSet<int>();
void Start()
{
hs1.Add(1);
hs1.Add(2);
hs1.Add(2);//重复的不插入
Debug.Log(hs1.Count);//输出2
hs2.Add(1);
hs2.Add(3);
//hs1.IntersectWith(hs2);//交集 输出1
//hs1.UnionWith(hs2);//并集 输出1 2 3
//hs1.ExceptWith(hs2);//差集 输出2
hs1.SymmetricExceptWith(hs2);//对称差集//输出3 2
foreach (var v in hs1)
{
Debug.Log("遍历:"+v);
}
}
}
数据结构_hashset
最新推荐文章于 2024-07-23 23:36:48 发布