Reverse A Stack
Note:
This code was written during a crunch period and isn't perfect. There will
be some errant spacing, some files will be
using namespace std,
etc. But it's all still usable and can be a
handy guideline if you're learning Data Structures.
#include <vector>
#include <stack>
#include <stdlib.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
std::stack<int> stackA;
std::stack<int> stackB;
for (int x : values)
{
stackA.push(x);
}
while (!stackA.empty())
{
stackB.push(stackA.top());
stackA.pop();
}
std::cout << "B:" << std::endl;
while (!stackB.empty())
{
std::cout << stackB.top() << " ";
stackB.pop();
}
return 0;
}