1

Learning about data structures in details. Checked few js tutorials online and they seemed to use array for everything.

Like this:

class Stack { 

    // Array is used to implement stack 
    constructor() 
    { 
        this.items = []; 
    } 

    // Functions to be implemented 
    // push(item) 
    // pop() 
    // peek() 
    // isEmpty() 
    // printStack() 
} 
vikas95prasad
  • 1,234
  • 1
  • 12
  • 37
  • Does this answer your question? [How do you implement a Stack and a Queue in JavaScript?](https://stackoverflow.com/questions/1590247/how-do-you-implement-a-stack-and-a-queue-in-javascript) – GrafiCode Jan 03 '20 at 12:12
  • Yes. Javascript arrays behave like linked lists in low-level languages – slebetman Jan 03 '20 at 12:13
  • `Array::pop()` and `Array::shift()` let you handle an array as stack or queue – GrafiCode Jan 03 '20 at 12:14
  • A stack - use a regular array and use the `.push()` and `.pop()` methods. A queue - use a regular array and use the `.push()` and `.shift()` methods. Almost everyone simply use the arrays directly instead of wrapping them in an extra object layer – slebetman Jan 03 '20 at 12:14

1 Answers1

1

Actually, there is no existing object containers for the likes of stack and queue but there are a handful of techniques on how you efficiently implement them.

refer to these links: https://chevtek.io/9-javascript-tips-you-may-not-know/ https://yuiazu.net/2019/02/19/stack-and-queue-in-javascript/

hope this helps :)

JadeAian
  • 69
  • 5