• 0

Implement a stack using javascript

Problem description :

Create a stack data structure in javascript.

  • Stack organizes data into the sequential order. It similar to the stack of books in a library or stack of dishes in the kitchen as shown below.
tall-stack-of-books-min

Logic :

  • It is similar to linked list. Linked list has a head attribute whereas Stack has top attribute.

  • Linked list is usually visualized horizontally from (left to right ) whereas Stack is visualized vertically (from bottom to top).

  • Stack data structure supports two basic operations : push and pop as shown below.

stack-min

Solution :