Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdlib>
- using namespace std;
- class IntSet{
- public:
- IntSet(int n){
- this->n=n+1;
- i=0;
- }
- void add(int u){
- if(i<=n){
- for(int j=0;j<=i;j++)
- if(v[j] == u){
- cout<<"Elementul exista deja in multime"<<endl;
- return;
- }
- i++;
- v[i]=u;
- }
- }
- void remove(int u){
- for(int j=0;j<=i;j++)
- if(v[j] == u){
- for(int k=j;k<=i;k++)
- v[k]=v[k+1];
- v[i]=0;
- i--;
- return;
- }
- }
- bool contains(int u){
- for(int j=0;j<=i;j++)
- if(v[j] == u){
- return true;
- }
- return false;
- }
- void toString(){
- for(int j=1;j<=i;j++){
- cout<<v[j]<<" ";
- }
- cout<<endl;
- }
- private:
- int v[100];
- int n;
- int i;
- };
- int main()
- {
- IntSet a = IntSet(5);
- a.add(4);
- a.add(2);
- a.add(1);
- a.remove(4);
- a.toString();
- cout<< a.contains(2) <<endl;
- cout<< a.contains(4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement