Stack method: Last in First Outside
Questing method: FIRST in FIRST OUTSIDE
The specific application is as follows:
Copy code code as follows:
<! Doctype HTML PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/xhtml1/dtddml1-transitationAl.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<Title> Stack Method </Title>
<script type = "text/javascript">
// The stack is a lifo (Last in FIRST OUTSIDE).
function basicpushorpop () {
var colors = ["red", "green", "blue"];
var count = colors.push ("pink"); // push () method can receive any number of parameters, add them one by one to the end of the data, and return to the length of the array after modification
alert (count);
VAR TEMP = colors.pop (); // Pop () method removes the last item from the end of the array, reduce the length value of the array, and then return the removal item item
alert (temp);
}
// The access rules for the queue data structure are FIFO (First in FIRST OUTSIDE)
function basicshift () {
var colors = new array ();
var count = colors.push ("red", "block"); // push two items
alert (count);
var test = colors.shift (); // The first item of the queue taken by the queue and remove
alert ("The current array length is:"+colors.length+"-removed items:"+test);
var newcount = colors.unshift ("" green "," black "); // UNSHIFT method indicates to add any type of any type of type to the front end of the queue, and return the new array length
Alert ("The length of the array is:"+newcount); // ie UNSHIFT method always returns UNDEFINED
}
</script>
</head>
<body>
<input type = "Button" value = "Stack method" onClick = "Basicpushorpop ();" />
<input type = "Button" value = "queue method" onClick = "basicshift ();" />
</body>
</html>