Stacks

What are stacks?

Stacks are data structures made up of nodes (single or double). They follow the Last In First Out (LIFO) principle, where adding the stack pushes all nodes down and the last element to be added is the first one to remove.

A java stack has a push function that adds the data to the beginning of the stack, a size function that returns the number of items on the stack, a peek function that returns the data stored in the front of the list, an isEmpty function to check if it has items, a pop function that removes and returns the first item in the list, and a toString function that converts the data into a printable string. 

Stacks have no insert functions and cannot remove a specific value. 

Examples: undo/redo for software applications, keeping track of math functions (order of operations)

Full course
Next Lesson