Stack method LIFO - FIFO method Team

1, a stack method of
LIFO (Last-In-First- Out, LIFO) recently added first removed. Insert stack (called a push) and removal of items (called a pop) occurs only in a top position of Zhan ---.
Analog: push () mode may receive any number of parameters, it is added to the end of the array individually, and modify the length of the array. pop () method from the last one end of an array, and reducing the length

var colors = new Array (); // create an array
var count = colors.push('red','green'); // count -> 2 colors -> ["red", "green"]
count = colors.push('black'); // count -> 3 colors -> ["red", "green","black"]

var item = colors.pop(); //"black" length -> 2


2, team method
FIFO (First-In-First- Out, FIFO)
queue at the end of the list to add items, remove items from the front end of the list of
simulation: push () mode may receive any number of parameters, it is added to the end of the array individually and modify the length of the array. shift (first removing the array) and the return, and the length-1

var colors = new Array (); // create an array 
var count = colors.push ( "red", "green"); // push two // count -> 2

count = colors.push ( "black"); // push another // count -> 3 

var item = colors.shift (); // first obtaining // item -> red colors -> [ "green", "black"]


Reverse queue
the unshift () and shift () reverse transformation, is added to any of the array, the array before the unshift () and pop () direction while using analog queue
the unshift () returns an array of length after adding

Guess you like

Origin www.cnblogs.com/hongding/p/11005115.html