Hello all, I am trying to design the logic for a program that allows a user to enter 10 numbers, then displays them in the reverse order of their entry. This is in pseudocode.

Thanks for your suggestions!

6 Years
Discussion Span
Last Post by -VLV-

Are you familiar with stacks?
A stack is a data structure that is accessed only by it's last element.
The simplest stack is made with an array and a "top" index.
When you start, you can set the top index to zero.
To add data to the stack, you "push" it on.
To push, you simply do this:

function push(data)
    if top>stack.size
    end if
end function

To get data from a stack, you pop it.

function pop()
    if top>0
        return stack[top]
    end if
end function

So what you do is push ten values, then pop them back. Try it.


For pseudocode you dont have to write in any specific programming language. Just write for example :

i = lastitem...firstitem


Declare an Array with the size of 10
Declare a variable, Var1

!A loop for the input

For Var1=1,10,1 !(For Start_Value,End_Value,Step)

...Receive the Input and store it in the Array, in the position of the Var1

End For

For Var1=10,1,-1 !(Invert the order...)

...Print the values previously stored in the array, in the position of the Var1

End For

!And that's it!


In Fortran it would look like this (not 100% accurate, but if u know Fortran u'll get the point, xD):

Real :: Var1, Array(10)

For Var1=1,10,1
    Read*, Array(Var1)
    End For
For Var1=10,1,-1
    Print*, Array(Var1)
    End For

Hope it Helps

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.