-
Notifications
You must be signed in to change notification settings - Fork 0
/
Quiz.cpp
77 lines (59 loc) · 1.31 KB
/
Quiz.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
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
// Programmer : Morayo Ogunsina
// Section : #002
// Lab : #9
// Date : April 6, 2016
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
using namespace std;
/** Boolean function to check if the length of a string is less than another */
void reverse(vector<int> vec, vector<int> &res, int low, int high, int index1, int index2);
void removeNegative(stack <int> stak);
int main()
{
vector <int> vec1, vec2;
stack<int> vec3;
vec1.push_back(1);
vec1.push_back(2);
vec1.push_back(4);
vec1.push_back(6);
vec1.push_back(5);
vec2 = vec1;
reverse(vec1, vec2, 1, 3, 1, 3);
for (int i = 0; i < vec2.size(); i++)
{
cout << vec2[i] << endl;
}
vec3.push(30);
vec3.push(16);
vec3.push(-18);
vec3.push(8);
vec3.push(-3);
removeNegative(vec3);
}
void reverse(vector<int> vec, vector<int> &res, int low, int high, int index1, int index2)
{
if (index1 == high+1)
{
return;
}
else
{
res[index1] = vec[index2];
}
reverse(vec, res, low, high, index1+1, index2-1);
}
void removeNegative(stack<int> stk)
{
//for (int i = 0; i < stk.size(); i++)
while (!stk.empty())
{
if (stk.top() < 0)
stk.pop();
else
cout << stk.top() << endl;
}
}