-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset.h
54 lines (47 loc) · 1.49 KB
/
set.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef SET_H
#define SET_H
#include <exception>
#include <iostream>
#include <vector>
#include <time.h>
#include "read.hpp"
#include <string>
inline bool valid(int a){return true;}
class Set{
public:
Set(): cnt_evens(0){
setEmpty();
}
friend std::istream& operator>>(std::istream& s, int& e)
{
e=read("Element: ","Integer is needed!",valid);
s>>e;
return s;
}
friend std::ostream& operator<<(std::ostream& s, const Set& e)
{
for(int x : e._vec){
s<<x<<" ";
}
return s;
}
class NonExistingElementException : public std::exception{};
class ExistingElementException : public std::exception{};
class EmptySetException : public std::exception{};
void setEmpty(){_vec.clear();};
int count() const {return _vec.size();}
void insert(int a);
void remove(int b) throw(std::exception);
bool isEmpty()const {return _vec.size()==0;}
bool isIn(int c)const;
int rand_elem()const throw(std::exception);
int evens()const;
int getEvens(){return cnt_evens;}
std::vector<int> getSet() const;
bool getSearch(int x,unsigned int& ano) const{return search(x, ano);}
private:
std::vector<int> _vec;
bool search(int m, unsigned int &ind) const;
int cnt_evens;
};
#endif // SET_H