1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mashcka [7]
3 years ago
12

Recall that within the ArrayBoundedQueue the front variable and the rear variable hold the indices of the elements array where t

he 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
Computers and Technology
1 answer:
Citrus2011 [14]3 years ago
6 0

Answer:

int n = elements.length;

if(rear < n) {

rear = (rear + 1) % n;

elements[rear] = element;

rear = rear + 1;

}

Explanation:

Options are not made available; However, I'll answer the question base on the following assumptions.

Assumptions

Array name = elements

The front and the rear variable hold the current indices elements

Element to enqueue is "element" without the quotes

To enqueue means to add an element to an already existing queue or to a new queue.

But first, the queue needs to be checked if it can accept a new element or not; in other words, if it's full or not

To do this, we check: if rear < the length of the queue

If this statement is true then it means the array can accept a new element; the new element will be stored at elements[rear] and the rear will be icremented by 1 rear by 1

Else if the statement is false, then an overflow is said to have occurred and the element will not be added.

Going by the above explanation, we have

int n = elements.length;

if(rear < n) {

rear = (rear + 1) % n;

elements[rear] = element;

rear = rear + 1;

}

Additional explanation:

The first line calculates the length of the queue

The if condition on line 2 tests if the array can still accept an element or not

Let's assume this statement is true, then we move to liine 3

Line 3 determines the new position of rear.

Let's assume that n = 6 and current rear is 4.

Line 3 will produce the following result;

rear = (rear + 1) % n;

rear = (4 + 1)% 6

rear = 5%6

rear = 5.

So, the new element will be added at the 5th index

Then line 4 will be equivalent to:

elements[rear] = element;

elements[5] = element;

Meaning that the new element will be enqueued at the 5th index.

Lastly, rear is incremented by 1 to denote the new position where new element can be added.

You might be interested in
Why do computers use binary code?
Anna71 [15]

Answer:

To make sense of complicated data, your computer has to encode it in binary. Binary is a base 2 number system. Base 2 means there are only two digits—1 and 0—which correspond to the on and off states your computer can understand

4 0
2 years ago
Read 2 more answers
You want to copy data from one cell or range to an adjacent cell or range in your spreadsheet, without using a shortcut key. Whi
astraxan [27]

How can you insert a new row into your data without disturbing an adjacent set of data on the same sheet? Highlight only the data where you'd like to insert a row. Right-click > Insert > Shift cells down.

3 0
2 years ago
A type of cpu socket, used with modern intel processors, where the cpu itself has no pins but the contact pads of the cpu line u
yawa3891 [41]
<span>A type of cpu socket, used with modern intel processors, where the cpu itself has no pins but the contact pads of the cpu line up with socket pins on the motherboard, is known as LGA.  </span>The Land Grid Array (LGA<span>) is a type of surface-mount packaging for ICs (</span> integrated circuits)<span> that is notable for having the pins on the </span>socket<span> (when a </span>socket is used) rather than the integrated circuit.
3 0
3 years ago
Read 2 more answers
Build three classes that conform to the following interfaces. Use arrays in creating your classes (e.g., do not use the built-in
daser333 [38]

Explanation:

public class ArrayList {

private Object[] array = new Object[1];

/**

 * Places new element at location

 * @param c, element to be inserted

 * @param i, location it is to be placed

 */

public void insert(char c, int i) {

 if(i>this.size()){

  System.out.println("Index "+i +" outside of list size; max: " +this.size());

  System.exit(0);

 }

 int count = 0;

 try {

  Object[] other = new Object[this.array.length+1];

  switch(i){

     case 0:{

      other[0] = c;

      for(int j=1;j<this.array.length;j++)

       other[j] = this.array[j-1];

       

      this.array = other;

      break;

     }

     default: {

      for(int j=0;j<i;j++)

       other[j] = this.array[j];

      other[i] = c;

      for(int k=i+1;k<this.array.length;k++)

       other[k] = this.array[k-1];

      this.array = other;

      break;

     }

     }

 }

 catch(ArrayIndexOutOfBoundsException exception) {

     largerArray();

     if(++count == 2){

      System.out.println("Something went wrong.");

      System.exit(0);

     }  

 }

}

 

/**

 * Places new element at location

 * @param object, element to be inserted

 * @param index, location it is to be placed

 */

void insert(Object object, int index){

 if(index>this.size()){

  System.out.println("Index "+index +" outside of list size; max: " +this.size());

  System.exit(0);

 }

 int count = 0;

 try {

  Object[] other = new Object[this.array.length+1];

  switch(index){

     case 0:{

      other[0] = object;

      for(int j=1;j<this.array.length;j++)

       other[j] = this.array[j-1];

       

      this.array = other;

      break;

     }

     default: {

      for(int j=0;j<index;j++)

       other[j] = this.array[j];

      other[index] = object;

      for(int k=index+1;k<this.array.length;k++)

       other[k] = this.array[k];

      this.array = other;

      break;

     }

     }

 }

 catch(ArrayIndexOutOfBoundsException exception) {

     largerArray();

     if(++count == 2){

      System.out.println("Something went wrong.");

      System.exit(0);

     }  

 }

}

 

/**

 * Removes element at index

 * @param index, location to remove

 * @return temp, object removed

 */

Object remove(int index){

 if(index>this.size()){

  System.out.println("Index "+index +" outside of list size; max: " +this.size());

  System.exit(0);

 }

 Object temp = this.array[index];

 int count = 0;

 try {

  Object[] other = new Object[this.array.length-1];

  switch(index){

     case 0:{

      other[0] = this.array[1];

      for(int j=1;j<this.size();j++)

       other[j] = this.array[j+1];

       

      this.array = other;

      break;

     }

     default: {

      for(int j=0;j<index;j++)

       other[j] = this.array[j];

      for(int k=index;k<this.size();k++)

       other[k] = this.array[k+1];

      this.array = other;

      break;

     }

     }

 }

 catch(ArrayIndexOutOfBoundsException exception) {

     largerArray();

     if(++count == 2){

      System.out.println("Something went wrong.");

      System.exit(0);

     }  

 }

 return temp;

}

 

/**

 * Copies the array to a new array twice the size.

 */

public void largerArray(){

 Object[] other = new Object[this.array.length*2];

 System.arraycopy(this.array, 0, other, 0, this.array.length);

 this.array = other;

}

 

/**

 * @return true if there are null elements

 */

public boolean isEmpty() {

 boolean bool = true;

 for (Object element : this.array) {

  if(element!=null){

   bool = false;

   break;

  }

  else{

   bool = true;

   break;

 }

 }

 return bool;

}

 

/**

 * Determines the real length of the array

 * @return length of non-null elements

 */

public int size(){

 int count = 0;

 for(int i=0;i<this.array.length;i++){

  if(this.array[i]==null)

   continue;

  else

   count++;

 }

 return count;

}

 

/**

 * Converts array to string.

 * @return the Array as a string

 */

public String toString(){

 String string = "";

 for(int i=0;i<this.size();i++){

  if(i<this.size()-1)

   string += this.array[i]+", ";

  else

   string += this.array[i];

 }

 return string;

}

 

/**

 * Similar to get, imput the character, retrieve index.

 * @param object, what we're looking for

 * @return index

 */

int indexOf(Object object){

 int index = -1;

 for(int i=0;i<this.array.length;i++){

  if(this.array[i]==(object))

   index = i;

  else continue;

 }

 return index;

}

 

/**

 * @param object, Arraylist tyoe

 * @return true, if the elements of the arrays are equivalent.

 */

public boolean equals(ArrayList object){

 boolean bool = false;

 int thisLength = this.array.length;

 int objectLength = object.array.length;

 if(thisLength > objectLength){

  for(int i=0;i<this.array.length;i++)

   if(this.array[i] == object.array[i])

    bool = true;

   else{

    bool = false;

    break;

   }

 }

 else{

  for(int i=0;i<object.array.length;i++)

   if(this.array[i] == object.array[i])

    bool = true;

   else{

    bool = false;

    break;

   }

 }

 return bool;

}

 

/**

 * Getter to check what is at an index

 * @param index, location

 * @return the character at this position

 */

Object get(int index){

 return this.array[index];

}

}

6 0
2 years ago
The security manager assigned a new security administrator the task of implementing secure protocols on all wireless access poin
Marysya12 [62]

Answer:

Good choice, as its one of the most secure wireless communications encryption methods, even though WPA2 would be the best

Explanation:

8 0
3 years ago
Other questions:
  • Which OS, in your opinion, manages multiprocessing in the most efficient manner?
    14·1 answer
  • Maya enjoys connectedWith her friends and social media apps but one of her friends post a lot of stuff that my thinks it’s annoy
    14·1 answer
  • What is the difference between an embedded image and an attached image
    7·2 answers
  • What is the purpose of the BBC option in a email?
    7·1 answer
  • Does a BIOS reset erase data such as pictures, programs or other things like that?
    13·1 answer
  • What is the purpose of exporting your public key to the directory services server?
    11·1 answer
  • A method that receives a two-dimensional array uses two ____ pairs following the data type in the parameter list of the method h
    11·1 answer
  • Which of the following actions might contribute to recommendations you see online?
    6·1 answer
  • You have three users who travel to four branch offices often and need to log on to the RODCs at these offices. The branch office
    12·1 answer
  • Create an application named TurningDemo that creates instances of four classes: Page, Corner, Pancake, and Leaf. Create an inter
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!