Recall that within the ArrayBoundedQueue the front variable and the rear variable hold the indices of the elements array where the current front and rear elements, respectively, of the queue are stored. Which of the following code sequences could be used to correctly enqueue element into the queue, assuming that enqueue is called on a non-full queue and that the code also correctly increments numElements?

a. numElements++; elements[rear) - element:
b. front++; elements(front) - element:
c. rear = (rear + 1) % elements.length; elements[rear) - element;
d. front = (front + 1) % elements.length; elements[front) - element;

Answers

Answer 1

Answer:

c. rear = (rear + 1) % elements.length; elements[rear] = element;

Explanation:

In the above statement:

Name of the array is elements.

rear holds current index of elements array where current rear element of queue is stored. Front are rear are two open ends of the queue and the end from which the element is inserted into the queue is called rear.

element is the element that is required to enqueue into the queue

Enqueue basically mean to add an element to a queue.

Here it is assumed that the queue is not full. This means an element can be added to the queue.

It is also assumed that code also correctly increments numElements.

rear = (rear + 1) % elements.length; This statement adds 1 to the rear and takes the modulus of rear+1 to the length of the array elements[]. This statement specifies the new position of the rear.

Now that the new position of rear is found using the above statement. Next the element can be enqueued to that new rear position using the following statement:

elements[rear] = element; this statement sets the element at the rear-th (new position) index of elements[] array.

For example we have a queue of length 5 and there are already 4 elements inserted into this queue. We have to add a new element i.e. 6 to the queue. There are four elements in elements[] array and length of the array is 5 so this means the queue is not full. Lets say that rear = 3

elements.length = 5

rear = 3

Using above two statements we get.

rear = (rear + 1) % elements.length;

       = 3 + 1 % 5

       = 4%5

      =  4

This computes the new position of rear. So the new position of rear is the 4-th index of elements[]. Now next statement:

elements[rear] = element;

elements[4] = 6

This statement adds element 6 to the 4-th index of elements[] array.

Thus the above statement enqueues element (element 6 in above example) into the queue.


Related Questions

3.16 (Gas Mileage) Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a program that will input the miles driven and gallons used for each tankful. The program should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the program should calculate and print the combined miles per gallon obtained for all tankfuls. Here is a sample input/output dialog:

Answers

Answer:

I am writing a C program.

#include <stdio.h> // for using input output functions

#include <stdbool.h> // for using a bool value as data type

int main() { // start of the main() function body

 int count=0; //count the number of entries

 double gallons, miles, MilesperGallon, combined_avg, sum; //declare variables

 while(true) {// takes input gallons and miles value from user and computes avg miles per gallon

      printf( "Enter the gallons used (-1 to stop): \n" ); //prompts user to enter value of gallons or enter -1 to stop

      scanf( "%lf", &gallons );//reads the value of gallons from user

   if ( gallons == -1 ) {// if user enters -1

     combined_avg = sum / count; //displays the combined average by dividing total of miles per drives to no of entries

     printf( "Combined miles per gallon for all tankfuls:  %lf\n", combined_avg ); //displays overall average value  

     break;} //ends the loop

     printf( "Enter the miles driven: \n" ); //if user does not enter -1 then prompts the user to enter value of miles

     scanf( "%lf", &miles ); //read the value of miles from user

MilesperGallon = miles / gallons; //compute the miles per gallon

printf( "The miles per gallon for tankful:  %lf\n", MilesperGallon ); //display the computed value of miles per gallon

  sum += MilesperGallon; //adds all the computed miles per gallons values

   count += 1;  } } //counts number of tankfuls (input entries)

Explanation:

The program takes as input the miles driven and gallons used for each tankful. These values are stored in miles and gallons variables. The program calculates and displays the miles per gallon MilesperGallon obtained for each tankful by dividing the miles driven with the gallons used. The while loop continues to execute until the user enters -1. After user enters -1, the program calculates and prints the combined miles per gallon obtained for all tankful. At the computation of MilesperGallon for each tankful, the value of MilesperGallon are added and stored in sum variable. The count variable works as a counter which is incremented to 1 after each entry. For example if user enters values for miles and gallons and the program displays MilesperGallon then at the end of this iteration the value of count is incremented to 1. This value of incremented for each tankful and then these values are added. The program's output is attached.

A password checking system that disallows user passwords that are proper names or words that are normally included in a dictionary is an example of _____ with respect to security systems.

Answers

The answer is control

What is the absolute pathname of the YUM configuration file? REMEMBER: An absolute pathname begins with a forward slash

Answers

Answer:

/etc/yum.conf

Explanation:

The absolute pathname for YUM is /etc/yum.conf. The configuration file For yum and related utilities can be found there. The file has one compulsory section, and this section can be used to place Yum options with global effect, it could also have one or more sections, that can enable you to set repository-specific options.

What is a what if analysis in Excel example?

Answers

Answer:

What-If Analysis in Excel allows you to try out different values (scenarios) for formulas. The following example helps you master what-if analysis quickly and easily.

Assume you own a book store and have 100 books in storage. You sell a certain % for the highest price of $50 and a certain % for the lower price of $20.

(i really hope this is what u needed)

A hotel salesperson enters sales in a text file. Each line contains the following, separated by semicolons: The name of the client, the service sold (such as Dinner, Conference, Lodging, and so on), the amount of the sale, and the date of that event. Write a program that reads such a file and displays the total amount for each service category. Display an error if the file does not exist or the format is incorrect.

Answers

Answer:

Life can get busy and hectic, but relationships matter. What is an effective way of mending relationships that may have had been neglected?Life can get busy and hectic, but relationships matter. What is an effective way of mending relationships that may have had been neglected?

Explanation:

Life can get busy and hectic, but relationships matter. What is an effective way of mending relationships that may have had been neglected?Life can get busy and hectic, but relationships matter. What is an effective way of mending relationships that may have had been neglected?Life can get busy and hectic, but relationships matter. What is an effective way of mending relationships that may have had been neglected?Life can get busy and hectic, but relationships matter. What is an effective way of mending relationships that may have had been neglected?Life can get busy and hectic, but relationships matter. What is an effective way of mending relationships that may have had been neglected?

Steve wants to take charge of his finances. To do so, he must track his income and expenditures. To accurately calculate his take-home pay, Steve must use his __________.

Answers

Answer:brain

Explanation:

to think

Identify five key technologies/innovations and discuss their advantages and disadvantages to developing countries like Ghana.​

Answers

Answer:

The key technology/ innovation advantage and disadvantage can be defined as follows:

Explanation:

Following are the 5 innovations and technology, which promote the other development goals, like renewable energy, quality of jobs, and growth of economic with the good health and very well-being:

1) The use of crop monitoring drone technology promotes sustainable farming.  

2) The production of plastic brick including highways, floors, and houses.  

3) The new banking market or digital banking.  

4) E-commerce site.    

5) Renewable energy deployment such as solar panels.  

Advantage:

It simple insect control, disease, fertilizer, etc.   It helps in aid in environmental purification and job formation.It is also fast and easy,  Funds are transferred extremely easily through one account to another.  Minimal prices, quick customer developments, and competition in the industry.  It saves them money in the medium-haul, less servicing.

Disadvantage:

The drones are too expensive to use, so poor farmers can be cut off.  Specialist technicians and gaining popularity are required.  The financial services data can be distributed through many devices and therefore become more fragile.  The personal contact loss, theft, security problems, etc. The higher operating costs, geographical limitations, and so on.
Other Questions
Consider the reaction below.NH4 + H20 - NH3 + H30"Which is an acid-conjugate base pair?O NHA and NH3O NH4" and H30*O H20 and NH3O H20 and H20" Draw a line representing the "rise" and a line representing the "run" of the line. State the slope of the line in simplest form. Maya is interning at a law firm over the summer and is paid by the hour. If her hourly wage is $52, which equation represents the proportional relationship between the wages she earns (w) and the number of hours (h)? express each of the following decimal number in the p/q form (1)0.5 (2)3.8 A competitive recreational basketball player is interested in completing an assessment to serve as a baseline against which he can measure future improvements. Which test will BEST measure these sports skills A pharmaceutical company is working on a drug to slow the spread of Ebola. Which of the following should be the company's focus?a. Sanitizing the drinking waterb. Protecting the food supplyc. Person-to-person contactd. Killing the insect vector An annual salary is $45000. His tax free allowances total $13000. He has to pay a tax of 20% on his taxable income.The tax payable is? All of the following are assumptions facing opposing forces of reducing costs and adapting to local markets that international business people should be aware of except? Homogenous customer needs worldwide People around the world are willing to sacrifice preferences for lower prices and higher quality Economies of scale can be obtained in production and marketing through supplying worldwide Lowering international synergy and cost via the value chain matrix Gullett Corporation had $26,000 of raw materials on hand on November 1. During the month, the Corporation purchased an additional $75,000 of raw materials. The journal entry to record the purchase of raw materials would include a: how would you solve #81? 1. A test-tube has a diameter of 3cm. How many turns would a piece of thread of length90.42cm make round the test tube. (Taken= =).(3marks) . Identify each of the following as (i) part of an expansionary fiscal policy, (ii) part of a contractionary fiscal policy, or (iii) not part of fiscal policy. a. The personal income tax rate is lowered. b. Congress cuts spending on defense. c. College students are allowed to deduct tuition costs from their federal income taxes. d. The corporate income tax rate is lowered. e. The state of Nevada builds a new tollway in an attempt to expand employment and ease traffic in Las Vegas. Activity-based costing for a service companyCrosswinds Hospital plans to use activity-based costing to assign hospital indirect costs to the care of patients. The hospital has identified the following activities and activity rates for the hospital indirect costs:Activity Activity RateRoom and meals $240 per dayRadiology $215 per imagePharmacy $50 per physician orderChemistry lab $80 per testOperating room $1,000 per operating room hourThe activity usage information associated with the two patients is as follows:Patient Putin Patient UmitNumber of days 6 days 4 daysNumber of images 4 images 3 imagesNumber of physician orders 6 orders 2 ordersNumber of tests 5 tests 4 testsNumber of operating room hours8 hours 4 hoursComplete the Activity Table:A. Determine the activity rate for each activity. Enter these rates in the Activity Rate columns.B. Use the activity rates in (A) to determine the total and per-unit activity costs associated with patient. Scores made on a certain aptitude test by nursing students are approximately normally distributed with a mean of 500 and a variance of 10,000. If a person is about to take the test what is the probability that he or she will make a score of 650 or more? at the rate of 15 per 6 oz. bar of chocolate, how much would a pound These tables of values represent continuous functions. For which function will the y-values be the greatest for very large values of x? Read and choose the correct option to complete the sentence. Pablo, no sales con amigos y ests ________; visita a la terapeuta para recibir ayuda. activo contento saludable triste Please help. Ill mark you as brainliest if correct! HELP ME PLEASSSSEE On a winter morning, the temperature before sunrise was -10. The temperature then rose by 1 each hour for 7 hours before dropping by 2 each hour for 3 hours. What was the temperature, in degrees Fahrenheit, after 10 hours? Please help! "Create a real-life scenario involving an angle of elevation or depression. Draw an appropriate diagram and explain how to solve your example."