CrazyEngineers
  • How to initialize a stack

    sridhar t

    Member

    Updated: Oct 25, 2024
    Views: 1.1K
    using the operation pop and push set i to the second element from the top of the stack, leaving the stack to without its top two element
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • simplycoder

    MemberNov 24, 2012

    First of all Welcome to CE.

    I am not sure what your question really is. Is it that you want to know how to initialize a stack with no elements or that you want to know how to use push and pop instructions.

    For the first scenario(Initializing the stack), keep one variable named TOP which will signify the number of elements in the stack and according to the working of the stack, the programmer will have access to the element which corresponds with the TOP.

    sridhar t
    using the operation pop and push set i to the second element from the top of the stack, leaving the stack to without its top two element
    I interpret this as you want to push i to the second position
    a)with the top element.


    for a), you need to pop the top element, and store it in some variable , then push i and then push the element in variable back to the stack.

    If this answer doesn't help you then let us know what is your question with more clarity
    for that you can even use diagrams and upload them.
    Are you sure? This action cannot be undone.
    Cancel
  • Jeffrey Arulraj

    MemberNov 26, 2012

    I think I get your Error you forgot to decrement i when you poped your stack and so top is not showing the value you are pushing in later.

    I am not a DS guy if this is your prob do post here and #-Link-Snipped-# will guide you furthur
    Are you sure? This action cannot be undone.
    Cancel
  • sridhar t

    MemberNov 26, 2012

    if they given a post-fix expression how to write code for the implementing the post-fix expression to infix expression
    Are you sure? This action cannot be undone.
    Cancel
  • Jeffrey Arulraj

    MemberNov 26, 2012

    sridhar t
    if they given a post-fix expression how to write code for the implementing the post-fix expression to infix expression
    There is some problem here buddy Can you pls post what exactly is your problem we are a bit unclear here right now

    Sorry about that but more info from you can help us tackle this easier for you
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register