?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...

A startup company hired you to help them build a mobile application, that will ultimately store billions of images and videos in S3. The company is lean on funding, and wants to minimize operational costs, however, they have an aggressive marketing plan, and expect to double their current installation base every six months. Due to the nature of their business, they are expecting sudden and large increases in traffic to and from S3, and need to ensure that it can handle the performance needs of their application. What other information must you gather from this customer in order to determine whether S3 is the right option?

A. You must know how many customers the company has today, because this is critical in understanding what their customer base will be in two years. B. You must find out the total number of requests per second at peak usage. C. You must know the size of the individual objects being written to S3, in order to properly design the key namespace. D. In order to build the key namespace correctly, you must understand the total amount of storage needs for each S3 bucket.

Computer Science & Information Technology

Which of these is not a concern for environmental monitoring systems?

a. Able to communicate even if the email service was involved b. Able to reach responders in a timely manner c. Able to sustain operations during an environmental disaster d. Include signage noting live or automated review only

Computer Science & Information Technology