#include <iostream>
#include <stack>
using namespace std;
static void removeEvenElements(stack<int> &st) {
stack<int> tmp;
while (!st.empty()) {
int val = st.top();
if (val % 2 == 1)
tmp.push(val);
st.pop();
}
while (!tmp.empty()) {
st.push(tmp.top());
tmp.pop();
}
}
void printStack(stack<int> st) {
while (!st.empty()) {
cout << st.top() << ' ';
st.pop();
}
}
int main ()
{
stack<int> st;
for (int i = 0; i < 10; i++)
st.push(i);
printStack(st);
removeEvenElements(st);
cout << endl;
printStack(st);
return 0;
}
/*
run:
9 8 7 6 5 4 3 2 1 0
9 7 5 3 1
*/