About Stack

What is a Stack ?

Instructions

<aside> <img src="/icons/light-bulb_gray.svg" alt="/icons/light-bulb_gray.svg" width="40px" />

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” )

</aside>

When and Where is a Stack used ?

Complexity Analyses

Pushing O( 1 )
Popping O( 1 )
Peeking O( 1 )
Searching O( n )
Size O( 1 )