Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lab03;
- /**
- *
- * @author Nan Mihai
- */
- public class IntSet {
- int v[];
- int nr;
- public IntSet(int n) {
- this.v = new int[n];
- this.nr = 0;
- }
- public boolean contains(int x) {
- IntSet set = this;
- for(int i = 0; i < set.nr; i++) {
- if(set.v[i] == x) {
- return true;
- }
- }
- return false;
- }
- public void add(int x) {
- IntSet set = this;
- if(!set.contains(x)) {
- v[nr] = x;
- nr++;
- }
- }
- public String toString() {
- IntSet set = this;
- String s = "";
- for(int i = 0; i < set.nr; i++) {
- s += set.v[i] + " ";
- }
- s += "\n";
- return s;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment