answersLogoWhite

0


Best Answer

It is not possible to write a code to POP from the stack when there is no your stack implementation information.

Because of that I am going to talk more about Stack in computer architecture and there will be additional link to specific examples(-e).

In x86 architecture there is three registers (BP, SP and SS) which are connected with stack and only SP and SS is needed.

SS - Stack Segment (base register);

SP - Stack Pointer (offset);

This is how the POP instruction works:

# operand = [SS:SP] (top of the stack) # SP = SP + 2; (change SP to point to new top element)

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write an algorithm to remove an item from the top of the stack?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Algorithm for implementing push operation on stack?

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


How is the stack and stack pointer work?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.


Basic operation of stack and Queue?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


Write an algorithm for inserting data into an array so that existing data is moved up one position to make room for the new data Write a program that applies the algorithm?

Algorithm for Inserting(by Md.Asif Rahman BBA(MIS) University of Dhaka Insert(a[],n, loc, item) { for(i=(n-1), i>(loc-2), i--) a[i+1]=a[i] a[loc-1]=item n++ }


Can stack be as a pointer?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.

Related questions

How do you write a structured algorithm an a flowchart to calculate and the average of ten scores?

how to write a structured algorithm that input the name and price of an item and quantity and amount


Algorithm for implementing push operation on stack?

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


How is the stack and stack pointer work?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.


Basic operation of stack and Queue?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


Write an algorithm for inserting data into an array so that existing data is moved up one position to make room for the new data Write a program that applies the algorithm?

Algorithm for Inserting(by Md.Asif Rahman BBA(MIS) University of Dhaka Insert(a[],n, loc, item) { for(i=(n-1), i>(loc-2), i--) a[i+1]=a[i] a[loc-1]=item n++ }


Can stack be as a pointer?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Stack pointer is the pointer that points to the top of the stack or that points the item at the top of the stack and help in adding or deleting the item from the top of stack.


Distinct features of queue and stack?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


What to Compare and contrast between stack and queue?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


What difference between stack and queue?

A stack is a data structure in which last item inserted is taken out first . That's why they are known as LIFO (last in first out). Inserting an item in stack is termed as push and taking an item out from stack I s termed as pop. Some applications of stack are : Polish notation, reversing string, backtracking , quick sort algorithm etc. The queue is a linear data structure where operations od insertion and deletion are performed at separate ends also known as front and rear. Queue is a FIFO structure that is first in first out. Whenever a new item is added to queue, rear pointer is used. and the front pointer is used when an item is deleted from the queue.


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.


How do you unstack blocks in your inventory in minecraft?

You take the whole stack, and right click the stack onto a free inventory, crafting, furnace or chest slot. This will remove one item from the stack, and can be repeated if more items are to be seperated.


How do you write an algorithm to find the number of times a given ITEM occurs in LIST?

You can write any algorithm in any way you like. Many prefer pseudocode or flowcharts, others use prose or more formalized methods. For example, if you wanted to describe an algorithm to count the number of occurrences of a given item I in a given list L, I would propose the following pseudocode: let counter be 0. let the current item C be the first item in list L. while C == valid { if C matches I then increment counter set C to the next item in the list } return counter.