Stack: An ordered set of last in, first out (LIFO)
Queue: An ordered set of first in, Out (FIFO)------------------------------------------------------------------------------------------------------
Stack method declaration:First, useArrayTo save the elements in the stack.
sequence number |
method |
description |
1 |
push (element (s)) |
|
2 |
pop () |
|
3 |
peek () |
Returns the element at the top of the stack without any modifications to the stack |
4 |
isempty () |
|
5 |
clear () |
Remove all elements from the stack |
6 |
size () |
|
For collections, it is best to use size instead of length
the implementation of the stack:
Queue method declaration:First, useArrayTo save the elements in the stack.
Serial number |
Method |
Description |
1 |
Enqueue (Element (s)) |
Add one (or more) new items to the tail of the queue |
2 |
Dequeue () |
Removes the first (that is, the top of the queue) item in the queue and returns the removed element |
3 |
Front () |
Returns the first element in a queue--first added, no changes to the queue |
4 |
IsEmpty () |
Returns true if there are no elements in the queue, otherwise false |
5 |
Size () |
Returns the number of elements in the queue. The length property of the array is very similar |
implementation of the queue:
JavaScript data Structures-stacks and queues