?Briefly explain the process of using arrays as data stacks.

What will be an ideal response?


?Arrays can be used to store information in a data structure known as a stack in which new items are added to the top of the stack-or to the end of the array-much like a person clearing a dinner table adds dishes to the top of a stack of dirty plates. A stack data structure employs the last-in first-out (LIFO) principle in which the last items added to the stack are the first ones removed. Stack data structures are encountered when using the Undo feature of some software applications, in which the last command a user performed is the first command that is undone.?JavaScript supports several methods to allow a user to work with a stack of array items. For example, thepush()method appends new items to the end of an array. It has the syntax
array.push(values)
wherevaluesis a comma-separated list of values to be appended to the end of the array. To remove-or unstack-the last item, thepop()method is used, as follows:
array.pop()
The following set of commands demonstrates how to use thepush()andpop()methods to employ the LIFO principle by adding and then removing items from a data stack:
var x = ["a", "b", "c"];x.push("d", "e"); // x = ["a", "b", "c", "d", "e"]x.pop(); // x = ["a", "b", "c", "d"]x.pop(); // x = ["a", "b", "c"]
In this code, thepush()method adds two items to the end of the array, and then thepop()method removes those last items one at a time.
A queue, which employs the first-in-first-out (FIFO) principle in which the first item added to the data list is the first removed, is similar to a stack. An example of the FIFO principle in action is a line of people waiting to be served. For array data that should be treated as a queue, the shift() method is used, which is similar to the pop()method except that it removes the first array item, not the last item. JavaScript also supports the unshift() method, which inserts new items at the front of the array.

Computer Science & Information Technology

You might also like to view...

VoIP service is interrupted during a power failure

Indicate whether the statement is true or false

Computer Science & Information Technology

Which of the following steps can be taken to resolve limited or no network connectivity issues on a Windows computer? (Select TWO.)

A. Run msconfig and configure startup for Safe Mode. B. Verify the SOHO router is powered on and the port LEDs indicate connectivity. C. Use System Restore to create a system restore point. D. Run the dxdiag utility to verify DirectX is functioning properly. E. Verify the network cable between the computer and router is connected and not damaged.

Computer Science & Information Technology

Many individuals are using TV tuners as ________ to record television shows for future playback.

A. DVRs B. scanners C. LEDs D. QRs

Computer Science & Information Technology

Answer the following statement(s) true (T) or false (F)

1. Communication with an Ethernet device using Ethernet communications is not possible until the device is configured and/or the IP address for the device is known. 2. The 1769-L23s are available with embedded ControlNet communications. 3. All 1769 CompactLogix controllers are supplied with one serial and one Ethernet port. 4. DeviceNet communications require the separate purchase of the communications modules for insertion into a CompactLogix slot. 5. The CompactLogix Ethernet/IP address changes frequently after installing a network and configuring other devices on the network.

Computer Science & Information Technology