forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
svutil.cpp
49 lines (41 loc) · 1.18 KB
/
svutil.cpp
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
// utility functions for vectors of strings
#include "svutil.h"
// prints the strings in the vector
void svOutput ( const vector<string> &vect ) {
for (int i=0; i < vect.size(); ++i) {
cout << vect.at(i) << " ";
}
cout << endl;
}
// finds a string in a vector and returns its index
int svFind ( const vector<string> &vect, string s) {
for (int i=0; i < vect.size(); ++i) {
if ( vect.at(i) == s ) return i;
}
return -1;
}
// removes an element from the vector at index idx
// returns true if remove successful, otherwise false
bool svDeleteAt ( vector<string> &vect, int idx ) {
int lastIndex = vect.size()-1;
if ( idx < 0 || idx > lastIndex )
return false;
if ( idx == lastIndex )
vect.pop_back();
else {
string temp = vect.at(lastIndex);
vect.pop_back();
vect.at(idx) = temp;
}
return true;
}
// sorts a vector of string in ascending order
void svSort ( vector<string> &vect ) {
// not implemented yet
return;
}
// return the index of the largest string in range index start to end
int svFindMax( const vector<string> &vect, int start, int end ) {
// not implemented yet
return -1;
}