Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public class IntSetImpl implements IntSet {
  2.  
  3. private List<Integer> conjunto; //lista de inteiros
  4.  
  5. IntSetImpl ( ) {
  6.  
  7. this.conjunto = new ArrayList <Integer>(); //crio nova lista de inteiros vazia
  8.  
  9. }
  10.  
  11. void insert ( int x ) {
  12. this.conjunto.add(x);
  13. }
  14. void insertAll ( int [ ] v ){
  15. int count = 0;
  16. while (count < v.size ) {
  17. insert(v[count]);
  18. count++;
  19. }
  20. }
  21.  
  22. void remove ( int x ) {
  23. this.conjunto.remove(x);
  24. }
  25.  
  26. boolean isIn ( int x ) {
  27. return this.conjunto.contains(x);
  28. }
  29.  
  30. int size ( ) {
  31. return this.conjunto.size();
  32. }
  33.  
  34. void forAll ( Visitor v ) {
  35. int count = 0;
  36. while ( count < this.size() ) {
  37. v.visit( this.conjunto[count] );
  38. count++;
  39. }
  40. }
  41. }
  42.  
  43. class Vi implements Visitor {
  44.  
  45. int x;
  46.  
  47. Vi ( int x ) {
  48. this.x = x;
  49. }
  50.  
  51. void visit ( int x ) {
  52. System.out.println(x);
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement