0

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

Edited by mike_2000_17: Fixed formatting

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by JamieLynnSEO
0

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...

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.