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;
}

Recommended Answers

There is no such things as stackType use std::stack

Jump to Post

All 3 Replies

Are you familiar with [code] ...code tags... [/code]? When posting code, please use them to make your code more readable.

You'll have to describe your problem better. Saying

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.

is vague and unhelpful (plus it seems contradictory to me for some reason, which just adds to the confusion). What is the expected behavior and how does it differ from the observed behavior? Do you want it to sort in Ascending order and it's sorting in Descending? Is it sorting at all? Etc...

There is no such things as stackType use std::stack

commented: Mhm. +1

stackType was the only error i picked up as well. First person's got it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.