testset.java
来自「数据结构(java描述)课件(第二讲:线性结构)」· Java 代码 · 共 52 行
JAVA
52 行
public class TestSet{
public static void main(String[] args){
MySet os1 = new MySet ();
MySet os2 = new MySet ();
//add null, 0, 2, 5
os1.add(new Integer(0));
os1.add(null);
os1.add(new Integer(2));
os1.add(new Integer(0));
os1.add(new Integer(5));
os1.add(null);
os2.add(new Integer(5));
os2.add(new Integer(0));
os2.add(new Integer(2));
os2.add(null);
os2.add(new Integer(5));
os2.add(new Integer(2));
if (os1.include(os2))//os1包涵os2
{
if (os2.include(os1))
{
System.out.println("集合os1和os2相等");
}
else
{
System.out.println("集合os2是os1的子集");
}
}
else//os1不包涵os2
{
System.out.println("集合os1和不包涵os2");
if (os2.include(os1))//os2却包涵os1
{
System.out.println("集合os1是os2的子集");
}
else
{
System.out.println("集合os2和os1不相等");
}
}
System.out.print("os1中的元素:");
os1.print();
System.out.println();
System.out.print("os2中的元素:");
os2.print();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?