Stack and Queue

Why is it called Push and Pop?
Push method "pushes" a variable or object onto the stack/queue.
You can think of this as inserting a value into, but it is actually inserted to the begining of sequence or pushed on top of container.
in case of Stack it is pushed on top, in case of queue it is pushed on "one end" of sequence.

Poping means accessing this variable but in the same time the variable/object is removed form the container.
When you call pop You are acctualy accessing "The top" of container.
In case of Stack you are accessing last variable pushed, while in case of queue you're accesing first variable pushed.

that is LILO (last in last out) Queue
or LIFO (last in first out) Stack

This is similar as push_back() and at() methods in std::vector but it works different.


EDIT:
Why these names? why push, why pop?

Push is called push because it pushes on the top, that has nothing to do with inserting, inserting means inserting into middle or whatever place. push means "inserting" on the top or begining.

Pop is accessing the last element. no accessing the middle one, you can't do that. that why is it called pop.

English is not my mother tonque but I'm pretty confident that abowe explanation has the exact meaning in english.
Last edited on
Pop is accessing the last element
Nope, pop() returns nothing. It just kills the element.

http://en.wiktionary.org/wiki/pop#Etymology_1
http://www.etymonline.com/index.php?term=pop&allowed_in_frame=0

There seems to be several onomatopoeic words in English.
I have been told that the names push and pop, for stacks, come from (or were at least inspried by) real world stacks of plates being pushed onto and popped off spring loaded plate dispensers, as found in cafeterias.

Nicked from "Stacks - why PUSH and POP?"
http://stackoverflow.com/questions/420315/stacks-why-push-and-pop

In particular, the East Campus Commons Cafeteria at MIT had spring loaded stacks of plates in the 1957-1967 time frame. The terms PUSH and POP would have been in use by the Tech Model Railroad Club. I think this is the origin.
Last edited on
Topic archived. No new replies allowed.