Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The stack.cpp is the regular file with push, peek, pop, and so on.

What I have tried:

I need help in knowing how to modify the code in Stack.cpp (which is a standard stack) so it implements a stack so it fills the array from right to left
Posted
Updated 2-Apr-20 14:37pm
v3
Comments
Richard Deeming 2-Apr-20 16:36pm    
Removing the content of your question after it has been answered is extremely rude.
CPallini 3-Apr-20 2:54am    
Why don't you post the Stack.cpp code?

I'm not sure what you mean by filling the array "right to left". I presume it means in reverse order, in which case top would start at the SIZE of the stack and work its way down to 0, with the stack being full when it reaches -1.
 
Share this answer
 
v4
Comments
Greg Utas 2-Apr-20 13:53pm    
You just have to flip everything: + becomes - and vice versa, ++ becomes -- and vice versa, -1 becomes SIZE and vice versa...
Quote:
I need help in knowing how to modify the code in Stack.cpp (which is a standard stack) so it implements a stack so it fills the array from right to left

Advice: Never do this. Stack.cpp is optimized to be efficient the way it is done.
I don't know what is your need, but reading the stack in reverse order is not a problem.
rather than :
C++
for (i = Stack.bottom; i <= Stack.top; i++) {
    // do stuff
    }

you need to swap the values :
C++
for (i = Stack.top; i >= Stack.bottom; i--) {
    // do stuff
    }

The code is just to illustrate the principle.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900