Question
Please answer this exercise using java. SetImp.java public class SetImp implements Set{ private int set[]; private int count; public SetImp(){ set = new int[max]; count=0;
Please answer this exercise using java.
SetImp.java
public class SetImp implements Set{ private int set[]; private int count;
public SetImp(){ set = new int[max]; count=0; }
public SetImp(int size){ set = new int[size]; count=0; }
public void add(int num){ if(!(contains(num))) set[count++]=num; }
private boolean contains(int num){ boolean ans=false; for(int i=0;i public void display(){ System.out.print("{"); for(int i=0;i public Set union(Set s){ Set s1 = new SetImp(); for(int i=0;i //public Set intersection(Set s); //public Set difference(Set s); //public boolean subset(Set s); //public boolean disjoint(Set s); //public int cardinality(); /*public static void main(String[] args){ Set set1 = new SetImp(); Set set2 = new SetImp(); Set set3 = new SetImp(); set1.add(1); set1.add(2); set1.add(3); set2.add(1); set2.add(4); set2.add(5); set1.display(); set2.display(); set3=set1.union(set2); set3.display(); }*/ }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started