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]
2 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]2 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
A web application starts when a client sends _______ to a server?
vovangra [49]
A web application starts when a client sends a request to a server
6 0
3 years ago
What command displays detail information about the OSPF interfaces, including the authentication method?
statuscvo [17]
<span>The answer is Show IP OSPF interface

Hope this helped :)</span>
8 0
3 years ago
Read 2 more answers
How can you skillfully use the internet for research
elena-s [515]

By looking up your research on websites that have (.org) or wikipedia for answers u might have to find information

6 0
3 years ago
When breaking a problem down, you often encounter elements that you want to use repeatedly in your code. Sometimes it's appropri
ddd [48]

<u>Answer:</u>

<em>FUNCTION:</em>

  • A function does not require the number of times that the <em>code script needs to be executed </em>
  • When we go for large programming, ie. while creating projects, we can invoke function from one file to another based on the access <em>specifier mentioned for the function. </em>
  • There is a stack call created in the memory whenever a <em>function is called. </em>

<em>LOOP :</em>

  • Whereas the number of times that the loop has to be <em>executed must be defined </em>
  • A loop cannot be called, it can be used only the code block in <em>which it is present. </em>
  • There is not overhead of creating a stack since it is not invoked and there is no <em>transfer of control from one module to another </em>

8 0
3 years ago
In 3–5 sentences, describe how good e-mail work habits increase workplace efficiency and productivity.
Ket [755]
Faster communication, information spread faster, group messages
6 0
3 years ago
Other questions:
  • The weird suspicious box that k12 sends the parents to put on the router. im getting strange privacy error messages on google an
    8·1 answer
  • What type of font color should Kim select if she chooses a dark-colored design theme for her presentation?
    14·2 answers
  • The _ are the devices that allow a computer system to communicate and interact with the outside world as well as store informati
    11·1 answer
  • ____ allows you to control how objects enter, move on and exit slides
    13·2 answers
  • A specialized security administrator responsible for performing systems development life cycle (SDLC) activities in the developm
    11·1 answer
  • Two technicians are discussing a parasitic load test. Technician A says that the parasitic load is measured with an ammeter Tech
    13·1 answer
  • How many strings with five or more characters can be formed from the letters in seeress?
    15·1 answer
  • In java
    6·1 answer
  • Channel logging tokens can be set to all but:________. a. Relaxed b. Strict c. Both versions d. None
    10·1 answer
  • 3) The director tells you to truck left, you must:
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!