The unshift () _method adds an element at the beginning of the array.
It is possible to add elements or change the elements by accessing the index value.
It is possible to remove an element from an Array. The _pop() _method to remove the last element from an array. The same method [_pop ()] also returns the returned value.
A queue is an ordered list of elements where an element is inserted at the end of the queue and is removed from the front of the queue. It follows the first-in, first-out (FIFO) principle
A queue has two main operations:
- Insert a new element at the end of the queue, which is called enqeue.
- Remove an element from the front of the queue, which is called dequeue.
- Add an element at the end of the array using the push() method. This method is equivalent to the enqueue operation.
- Remove an element from the front of an array using the _shift() _method. It is equivalent to the dequeue operation.
The implementation looks like this in Visual Code
The function “Queue ()” function helps store the elements using an array, while the “enqueue ()” helps add an element at the end of the queue, but the “push ()” of an array helps insert the new element at the end of the queue.
As a type of data structure, the stack helps keep a list of elements. It works based on the principle of Last In, First out (LIFO), to mean that the most recently added element is the first one to remove.
The stack has two operations: push and pop. The push put an element at the top of the stack while the pop removes an element from the top of the stack.
Linked List is a linear data structure. But its elements are not stored at the location. The elements are linked using the pointers. A linked list is a linear data structure that represents a collection of elements, where each element points to the next one. The first element in the linked list is the head and the last element is the tail.