|
March 29, 2000 Programming a FIFO Queue Tips: March 2000
Yehuda Shiran, Ph.D.
|
|
The shift() and unshift() methods are similar to the push() and pop() methods. The difference is that while the push() and pop() methods add and remove elements from the end of the array, the shift() and unshift() methods roll out and in elements from the beginning of the array. The push() and pop() methods support the Stack abstract data type, which is based on the LIFO (Last In First Out) model. The shift() and unshift() methods, on the other hand, support the FIFO (First In First Out) model.
The
The first line sets the returned value, the first element of the array. The
The last two lines decrement the size of the array by one and returned the value of the first element,
When the browser is a pre-5.5 version of Internet Explorer, we need to extend the Array's prototype with the new
We do nothing when the browser is IE 5.5 or higher. For other browsers or lower versions, we assign the home-brewed
The
We extract the number of new elements,
The second
When the browser is a pre-5.5 version, we need to extend the Array's prototype with the new
We do nothing when the browser is IE 5.5 or higher. For lower versions, we assign the home-brewed See a demo of the above methods in Column 59, IE 5.5: Formatting, URIs, and Stack Operations.
People who read this tip also read these tips: Look for similar tips by subject: |