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
kkurt [141]
3 years ago
6

Write the function evens which takes in a queue by reference and changes it to only contain the even elements. That is, if the q

ueue initially contains 3, 6, 1, 7, 8 then after calling odds, the queue will contain 6, 8. Note that the order of the elements in the queue remains the same. For full credit, no additional data structures (queues, stacks, vectors, etc.) should be used. Assume all libraries needed for your implementation have already been included.
Computers and Technology
1 answer:
kvv77 [185]3 years ago
3 0

Answer:

Explanation:

The following code is written in Java it goes through the queue that was passed as an argument, loops through it and removes all the odd numbers, leaving only the even numbers in the queue. It does not add any more data structures and finally returns the modified queue when its done.

  public static Queue<Integer> evens(Queue<Integer> queue) {

       int size = queue.size();

       for(int x = 1; x < size+1; x++) {

           if ((queue.peek() % 2) == 0) {

               queue.add(queue.peek());

               queue.remove();

           } else queue.remove();

       }

       return queue;

   }

You might be interested in
What are the five Ws?<br> (I don’t even know what this means)
Advocard [28]

Answer:

HII

Explanation:

Who, What, When Where, and Why.

3 0
3 years ago
Read 2 more answers
7) through: (0, 4) and (-1,0)​
Andreyy89

Answer:

its 5

Explanation:

7 0
3 years ago
What is the meaning of N.W.O​
Likurg_2 [28]

Answer:

The New World Order (NWO) in conspiracy theories is the hypothesis of a secretly emerging totalitarian world government.

8 0
3 years ago
. In the select algorithm that finds the median we divide the input elements into groups of 5. Will the algorithm work in linear
8090 [49]

Answer:

we have that it grows more quickly than linear.

Explanation:

It will still work if they are divided into groups of 77, because we will still know that the median of medians is less than at least 44 elements from half of the \lceil n / 7 \rceil⌈n/7⌉ groups, so, it is greater than roughly 4n / 144n/14 of the elements.

Similarly, it is less than roughly 4n / 144n/14 of the elements. So, we are never calling it recursively on more than 10n / 1410n/14 elements. T(n) \le T(n / 7) + T(10n / 14) + O(n)T(n)≤T(n/7)+T(10n/14)+O(n). So, we can show by substitution this is linear.

We guess T(n) < cnT(n)<cn for n < kn<k. Then, for m \ge km≥k,

\begin{aligned} T(m) & \le T(m / 7) + T(10m / 14) + O(m) \\ & \le cm(1 / 7 + 10 / 14) + O(m), \end{aligned}

T(m)

​

 

≤T(m/7)+T(10m/14)+O(m)

≤cm(1/7+10/14)+O(m),

​

therefore, as long as we have that the constant hidden in the big-Oh notation is less than c / 7c/7, we have the desired result.

Suppose now that we use groups of size 33 instead. So, For similar reasons, we have that the recurrence we are able to get is T(n) = T(\lceil n / 3 \rceil) + T(4n / 6) + O(n) \ge T(n / 3) + T(2n / 3) + O(n)T(n)=T(⌈n/3⌉)+T(4n/6)+O(n)≥T(n/3)+T(2n/3)+O(n) So, we will show it is \ge cn \lg n≥cnlgn.

\begin{aligned} T(m) & \ge c(m / 3)\lg (m / 3) + c(2m / 3) \lg (2m / 3) + O(m) \\ & \ge cm\lg m + O(m), \end{aligned}

T(m)

​

 

≥c(m/3)lg(m/3)+c(2m/3)lg(2m/3)+O(m)

≥cmlgm+O(m),

​

therefore, we have that it grows more quickly than linear.

5 0
3 years ago
]
loris [4]
B. Which promotes a chemical reaction
5 0
3 years ago
Other questions:
  • How many degrees of freedom does any unconstrained object have in 3-D modeling?
    6·1 answer
  • Which of the following is not a good way to conserve fuel and reduce emissions?
    13·2 answers
  • If everyone's choice for their computer printer were an hp laserjet 4100, there would be a ___ preference segment in the compute
    8·1 answer
  • In terms of online safety, what is the grooming process, (predators).
    5·2 answers
  • The media literacy movement hopes to _____.
    15·2 answers
  • Write a Java Program that can compute the mean, median, the highest, and the lowest of the students’ scores in a class. First, t
    6·1 answer
  • Which domain ending can only be used by the U.S. government?
    14·2 answers
  • During his last performance review, Franco's boss urged him to set some short-term and long-term sales goals to help him perform
    6·2 answers
  • Which of the following was (and still is) used by computer programmers as a first test program?
    13·2 answers
  • Name 3 supercomputers along with their cost, purpose and the country it is located.​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!