Dear Friends: I am having trouble with this exercise. I was able to compile and
create the list 0-7 and reverse. I am not sure where I went wrong.
Thanks
Danni
#include <stack>
#include <iostream>
using namespace std;
template <class stackType>
void reversedStack(const stackType & originalStack, stackType &reversedStack)
{
stackType anotherStack(originalStack);
while(!reversedStack.empty())
{
reversedStack.pop();
}
while(!anotherStack.empty())
{
reversedStack.push((T)anotherStack.top());
anotherStack.pop();
}
}
int main()
{
stackType<int> originalStack, reversedStack;
for (int i = 0; i < 8; i++ )
originalStack.push(i);
stackType<int> copyStack(originalStack);
cout << "My first stack counting down is " << endl;
while (!copyStack.empty())
{
int value = (int)copyStack.top();
copyStack.pop();
cout << value << endl;
}
for (int i = 50; i < 55; i++ )
reversedStack.push(i);
reversedStack(originalStack, reversedStack);
cout << "The reversed Stack counting up is " << endl;
while (!reversedStack.empty())
{
int value = (int)reversedStack.top();
reversedStack.pop();
cout << value << endl;
}
system("pause");
return 0;
}