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
|
void FillAVector(vector<int> &vector1);
void FindANumber(vector<int> &v1);
void RemoveANumber(vector<int> &v1);
void MakeAStack(list<int> &l1);
void RunPracticeFunctions()
{
vector<int> vector1 = { 2, 4, 4, 7, 8, 5, 6 };
cout << "Finding number: " << endl;
FindANumber(vector1);
printVector(vector1);
//FillAVector(vector1);
RemoveANumber(vector1);
printVector(vector1);
list<int> list1 = { 6, 8, 14, 3 };
MakeAStack(list1);
}
void FillAVector(vector<int> &v1)
{
fill(v1.begin() + 2, v1.end() - 1, 7);
ostream_iterator<int> screen(cout, " ");
cout << "Filled vector with 7's from first index to index: " << endl;
copy(v1.begin(), v1.end(), screen);
cout << endl;
}
void FindANumber(vector<int> &v1)
{
vector<int>::const_iterator iter = v1.begin();
iter = find(v1.begin(), v1.end(), 5);
if (iter != v1.end())
{
cout << "5 found at position " << (iter - v1.begin()) << endl;
}
else
cout << "5 not found in vector" << endl;
}
void RemoveANumber(vector<int> &v1)
{
vector<int>::iterator iter;
iter = remove(v1.begin(), v1.end(), 4);
}
void MakeAStack(list<int> &l1)
{
list<int>::const_iterator iter;
stack<int> s1;
for (iter = l1.begin(); iter != l1.end(); iter++)
{
s1.push(*iter);
}
while (s1.size() != 0)
{
cout << s1.top() << " ";
s1.pop();
}
}
|