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?
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.
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.
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.
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.
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:
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With