How to initialize a stack

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

Replies

  • simplycoder
    simplycoder
    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.
  • Jeffrey Arulraj
    Jeffrey Arulraj
    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
  • sridhar t
    sridhar t
    if they given a post-fix expression how to write code for the implementing the post-fix expression to infix expression
  • Jeffrey Arulraj
    Jeffrey Arulraj
    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

You are reading an archived discussion.

Related Posts

supercharging and turbocharging always increase the efficiency of an engine...can any one please explain me why only few cars are using this technology..(mostly small cars wont use)
hi i am new to ce and i am new to engg. too i have just started my engg in cse and iam exited about it 😁 😉
APU, that might be exotic term for some. APU also known as Accelerated Processing Unit is Processor fusion of CPU (Central Processing Unit) & GPU (Graphical Processing Unit). AMD has...
I have done overclocking my 2.90 GHz processor to 3.40 GHz (core-2-duo processor, I know it's outdated, okay ?😡) But check this out 8.176 GHz clockspeed !! defeating the previous...
After Hulu, Netflix & Amazon applications, now Youtube is also available for Wii U platform. The new app allows Wii U users watch & search videos using its gamepad &...