answersLogoWhite

0


Best Answer

1. If TOP = MAXSTK THEN [Stack already filled?]

Print "OVERFLOW"

Go to step 4

Endif

2. TOP = TOP + 1 [Increase TOP by 1]

3. Set ST[STOP] = ITEM [Insert ITEM in new TOP position]

4. End

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

Initialise top.

Int item.

If top == max-1

print stack overflow.

Else

print enter element.

Scan it to item.

Stack(top)=item.

Top =top +1.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

algorithm of pop

if(top==-1)

{

cout<<"\n the stack is empty";

}

else

return arr[top];

top--;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Algorithm for implementing push operation on stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why insert operation in stack called as push operation?

Consider an array used as a stack. Align this array vertically. When an element is inserted into the stack, it is pushed all the way down despite the space availability at the top. Hence it is called push operation. Here's an illustration:Stack initially:|_||_||_||5|Stack after the insertion of 6:|_||_||6| - element pushed down as much as possible|5|


What is push operation in data structure?

Push inserts a value onto the top of the stack. Pop extracts the top value from the stack. These are the two primary operations that can be performed upon a stack. Prior to popping a value, you will first check the stack is not empty, store the top value, then pop the stack. For a stack of type T, you might use the following: if (!stack.empty()) { T value {stack.top()}; // copy top value stack.pop(); // remove value from stack // use value... }


An algorithm to Reversing the order of elements on stack S using 1 additional stacks?

// stack to contain content Stack sourceStack = new Stack(); // ... fill sourceStack with content // stack to contain reversed content Stack targetStack = new Stack(); while (!sourceStack.empty()) { targetStack.push(sourceStack.pop()); } // targetStack contains the reversed content of sourceStack


What is time complexity of stack?

All major queue operations (push, pop and front) are constant time operations.


Define stack.discuss push and pop operation?

A stack is a region of memory that you store things, and retrieve them in the reverse order of storage. Think of it as a stack of papers. You write something down on a piece of paper, and then you put that paper in a stack, specifically on the top of the stack. This is called a push operation. If you want to go and do something else, such as service an interrupt or call another function, you create more pieces of paper and you push them onto the top of the stack as well. Under normal conditions, you cannot access anything on the stack below the top. I say "normal" because the architecture of the processor allows you to access chunks of memory contained within the stack, relative to the base pointer BP, allowing you to pass arguments and store temporary variables in what is called a stack frame. The reverse of push is called pop, and it is equivalent to taking a piece of paper off of the top of the stack and throwing it away - or using it, whatever you want - but that action exposes the next piece of paper, which is now the new "top of stack".

Related questions

What are the stack operation?

there are two operations you can do with a STACK one is PUSH operation and the other is POP operation


Why insert operation in stack called as push operation?

Consider an array used as a stack. Align this array vertically. When an element is inserted into the stack, it is pushed all the way down despite the space availability at the top. Hence it is called push operation. Here's an illustration:Stack initially:|_||_||_||5|Stack after the insertion of 6:|_||_||6| - element pushed down as much as possible|5|


What is push operation in data structure?

Push inserts a value onto the top of the stack. Pop extracts the top value from the stack. These are the two primary operations that can be performed upon a stack. Prior to popping a value, you will first check the stack is not empty, store the top value, then pop the stack. For a stack of type T, you might use the following: if (!stack.empty()) { T value {stack.top()}; // copy top value stack.pop(); // remove value from stack // use value... }


What is stack operation in 8085 microprocessor?

STACK operation in 8085 microprocessor.The stack is a reserved area of the memory in RAM where temporary information may be stored. An 8-bit stack pointer is used to hold the address of the most recent stack entry. This location which has the most recent entry is called as the top of the stack.When the information is written on the stack, the operation is called PUSH. When the information is read from the stack, the operation is called POP. The stack works on the principle of Last in First Out or Fist in Lat Out


What is stack in 8085 microprocessor?

STACK operation in 8085 microprocessor.The stack is a reserved area of the memory in RAM where temporary information may be stored. An 8-bit stack pointer is used to hold the address of the most recent stack entry. This location which has the most recent entry is called as the top of the stack.When the information is written on the stack, the operation is called PUSH. When the information is read from the stack, the operation is called POP. The stack works on the principle of Last in First Out or Fist in Lat Out


An algorithm to Reversing the order of elements on stack S using 1 additional stacks?

// stack to contain content Stack sourceStack = new Stack(); // ... fill sourceStack with content // stack to contain reversed content Stack targetStack = new Stack(); while (!sourceStack.empty()) { targetStack.push(sourceStack.pop()); } // targetStack contains the reversed content of sourceStack


What are the two methods to tell when the stack is full?

1. Operation 'push' returns with a STACK_FULL error code 2. Operation 'is_full' returns with TRUE


What is a stack and how do you represent a stack in computer memory also discuss basic operation performed on a stack?

A stack is an abstraction of First-in-last-out, or the last in first out. The basic operations (may bear different names) Push or Add Pop or Next


What is the function of the stack counter?

Its not a stack counter - its a stack pointer. The stack pointer is a register that points to the top of the stack. In the Intel configuration, it points to the next item to be popped off the stack. To push an item requires that the stack pointer be decremented first, and then the item is written. The inverse operation - the pop - requires read then increment.


What is time complexity of stack?

All major queue operations (push, pop and front) are constant time operations.


How do you use push operation in stack give the exampale of the program?

A stack can be implemented as an array or a list. If an array, simply push the new element onto the end of the array. If a list, point the new node at the head node then make the new node the new head of the list.


Define stack.discuss push and pop operation?

A stack is a region of memory that you store things, and retrieve them in the reverse order of storage. Think of it as a stack of papers. You write something down on a piece of paper, and then you put that paper in a stack, specifically on the top of the stack. This is called a push operation. If you want to go and do something else, such as service an interrupt or call another function, you create more pieces of paper and you push them onto the top of the stack as well. Under normal conditions, you cannot access anything on the stack below the top. I say "normal" because the architecture of the processor allows you to access chunks of memory contained within the stack, relative to the base pointer BP, allowing you to pass arguments and store temporary variables in what is called a stack frame. The reverse of push is called pop, and it is equivalent to taking a piece of paper off of the top of the stack and throwing it away - or using it, whatever you want - but that action exposes the next piece of paper, which is now the new "top of stack".