Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Set
- {
- private int[] s;
- private int tot, curr;
- public Set(int max)
- {
- tot = max;
- s = new int[tot];
- curr = 0;
- }
- public boolean add(int n)
- {
- for(int i = 0; i < s.length; i++)
- if(s[i] == n)
- for(int j = 0; j < s.length; j++)
- {
- if(curr < s.length && s[j] != n)
- {
- curr++;
- s[j] = n;
- return true;
- }
- else if(j >= 1 && curr < s.length && n != s[j - 1])
- {
- curr++;
- s[j] = n;
- return true;
- }
- }
- return false;
- }
- public boolean isMember(int n)
- {
- for(int i = 0; i < s.length; i++)
- if(s[i] == n)
- return true;
- return false;
- }
- public void show()
- {
- for(int i = 0; i < curr; i++)
- {
- if(curr == 0)
- {
- System.out.print("()");
- break;
- }
- if(curr != 0 && i == 0)
- System.out.print("(" + s[i] + ")" );
- else if(curr != 0 && i > 0)
- System.out.println("(" + s[i] + ")");
- }
- System.out.println();
- }
- public boolean isEmpty()
- {
- return (curr == 0);
- }
- public boolean isFull()
- {
- return (curr == s.length);
- }
- public boolean remove(int n)
- {
- int c = 0;
- for(int i = 0; i < s.length - 1; i++)
- {
- if(s[i] == n && curr != 0)
- {
- c = i;
- for(int j = c; j < s.length - 1; j++)
- s[j] = s[j + 1];
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement