Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is push()ing and pop()ping defined?

I know how the push() and pop() methods in a typical implementation of a Queue/Linked List work but what I do want to know is what you actually define as a push or a pop? When can you name a method push()/pop()? What makes the insert()/add() method in a typical Tree implementation not a push()?

My understanding is that push()ing means putting something to a position some special pointer is pointing to, and pop()ping an element means putting some object away some pointer is pointing to, but it doesn't seem to be clearly defined. Or does the naming matter at all?

like image 586
helpermethod Avatar asked May 10 '10 17:05

helpermethod


People also ask

What is push and pop definition?

Instructions that store and retrieve an item on a stack. Push enters an item on the stack, and pop retrieves an item, moving the rest of the items in the stack up one level.

How does push and pop work?

Push operation refers to inserting an element in the stack. Since there's only one position at which the new element can be inserted — Top of the stack, the new element is inserted at the top of the stack. Pop operation refers to the removal of an element.

What is the difference between Push and Pop Pop?

PUSH vs POPPUSH is used when you want to add more entries to a stack while POP is used to remove entries from it. A stack is so named because it places the individual data entries just like a stack of books. The first one goes to the bottom and you can only add or remove items at the top of the stack.

How does push and pop work in stack?

A push operation decrements the pointer and copies the data to the stack; a pop operation copies data from the stack and then increments the pointer. Each procedure called in the program stores procedure return information (in yellow) and local data (in other colors) by pushing them onto the stack.


1 Answers

When referring to operations on a linked list, you can push items on to the list to add them. You can then pop items off of a list to remove them.

If you pop items from the same end of the list that you add them, you have implemented a stack, or a Last-In-First-Out (LIFO) data structure:

Stack

If you pop items from the opposite end, then you have implemented a queue - although usually the terminology is "enqueue" and "dequeue". This is a First-In-First-Out (FIFO) data structure:

Queue

like image 134
Justin Ethier Avatar answered Feb 05 '23 20:02

Justin Ethier