Nerd For Tech
Published in

Nerd For Tech

Queues and Stacks

A queue is a data structure that works by only allowing you to insert elements at the rear of the list and then only allowing you to remove the elements from the front of the list. A queue is based on the first-in, first-out (FIFO) principle. A real-world example would be the line in a grocery store. The first people to get in line are the first ones to leave.

A stack is a data structure that works by only allowing elements to be inserted and deleted from the top of the list. A stack is based on the last-in, first-out (LIFO) principle. A real-world example of this is cafeteria trays. The last trays put out are the first ones that are taken.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store