1. public class IntSet 2. private Vector els; 3. //constructor 5. public IntSetO
ID: 3870672 • Letter: 1
Question
1. public class IntSet 2. private Vector els; 3. //constructor 5. public IntSetO 6. els = new Vector(); 8. 9. public void insert(int x) 10. I/Modifies: this 11. I/Effects: Adds x to the elements of this 12. 13. 14. public void remove(int x) 15. I/Modifies: this 16. l/Effects: removes x from this 18. public boolean isIn(int x)t 19. iaciret sre If i in h ers take 20. 21. 22. private getIndex(Integer x) 23. 24. 25. 26. public int sizeO 27. I/Effects: returns the cardinality of this 28.) 29. 30. public int choose0 throws EmptyExcpetionf 31. 32. //returns an arbitrary element of this 33. ) 34. //Effects: if x is in this returns index where x appears else /ireturns-1 //Effects: if this is empty throws EmptyException elseExplanation / Answer
Choic1 - Duplicates allowed:
Function affected will be as follows:
1.Remove(x)- We need to be checking all the elements of the vector
because of duplicate entries. We can not break if
we find the first occurence of that element
2. getIndex(x) - Here we need to decide which index we have to give
or we may have to give all the indexes because there
may be mutiple entries of x.
Choic2 - Duplicates disallowed:
There won't be any considerations in this case as all
the functions have clarity in their output.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.