- stack is one-ended linear data structure which models a real world stack by having two primary operations, namely Push and Pop . and named Last In First Out
- Explanation in an hour : ( 1:00:27 ) .
pop( ); // remove the first element in the data
push( “Onion” ); // add in the first element in the data
push( “Celery” )
push( “Watermelon”)
pop( )
pop( )
push( “Lettuce” )
- Used by undo mechanisms in text editors.
- Used in compiler syntax checking for matching brackets and braces.
- Can be used to model a pile of books or plates.
- Used behind the scenes to support recursion by keeping track of previous functions calls.
- Can be used to do a Depth First Search ( DFS ) on a graph.
| Pushing | O( 1 ) |
|---|---|
| Popping | O( 1 ) |
| Peeking | O( 1 ) |
| Searching | O( n ) |
| Size | O( 1 ) |
Explanation in a hour : ( 1:08:04 )