-
Notifications
You must be signed in to change notification settings - Fork 1
/
stringVec.h
77 lines (59 loc) · 1.46 KB
/
stringVec.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef __STRINGVEC__
#define __STRINGVEC__
#ifndef MAX_STRINGVEC_SIZE
#define MAX_STRINGVEC_SIZE 10
#endif
class StringVec{
public:
StringVec():_size(0){
this->clear();
};
inline void PushBack(const String& ss){
if(this->Size() == MAX_STRINGVEC_SIZE){
this->shift();
}
this->_s[this->Size()] = ss;
this->_size ++;
}
const int Find(const String& ss){
for(unsigned i = 0; i < this->Size(); i ++){
if(this->_s[i] == ss){
return i;
}
}
return -1;
}
void Erase(const int& pos){
if(pos < 0 || pos >= this->Size()) return;
for(unsigned int i = pos+1; i < this->Size(); i ++){
this->_s[i-1] = this->_s[i];
}
this->_size --;
}
const String shift(){
String s = this->_s[0];
if(this->Size() != 0){
for(unsigned int i = 1; i < this->Size(); i ++){
this->_s[i-1] = this->_s[i];
}
this->_size --;
}
return s;
}
void clear(){
for(unsigned int i = 0; i < this->Size(); i ++){
this->_s[i] = "";
}
}
inline const int Size(){
return this->_size;
}
String& operator[](int i){
if(i < 0 || i >= this->Size()) return this->_s[0];
return this->_s[i];
}
private:
String _s[MAX_STRINGVEC_SIZE];
int _size;
};
#endif //__STRINGVEC__