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
Your program Assignment Write a program that reads a sentence as input and converts each word to "Pig Latin". In one version of
xxTIMURxx [149]

Answer:

theSentence = input('Enter sentence: ')

theSentence = theSentence.split()

sentence_split_list =[]

for word in theSentence:

  sentence_split_list.append(word[1:]+word[0]+'ay')

sentence_split_list = ' '.join(sentence_split_list)

print(sentence_split_list)

Explanation:

Using the input function in python Programming language, the user is prompted to enter a sentence. The sentence is splited and and a new list is created with this statements;

theSentence = theSentence.split()

sentence_split_list =[ ]

In this way every word in the sentence becomes an element in this list and individual operations can be carried out on them

Using the append method and list slicing in the for loop, every word in the sentence is converted to a PIG LATIN

The attached screenshot shows the code and output.

5 0
3 years ago
Need help with python coding
Ivanshal [37]

Answer:

def= definition

Explanation:

7 0
3 years ago
Read 2 more answers
Which of the following computer component facilitates internet connection?
babunello [35]

Answer:

your answer may be(utility software)

8 0
2 years ago
Read 2 more answers
In microsoft word, when you highlight existing text you want to replace you are
RSB [31]
You are changing the word
8 0
2 years ago
What are the required components of a database function? ​
vagabundo [1.1K]

Answer:

Following are the required components of a database function :-

  • Software
  • Data
  • Hardware
  • Procedures
  • Data Manager
  • Database Access language
  • Query processor

hope it helps!

5 0
2 years ago
Other questions:
  • __ means having a current knowledge and understanding of computers, mobile devices, the web, and related technologies.
    8·1 answer
  • A. True
    7·1 answer
  • Which of the following attacks seeks to introduce erroneous or malicious entries into a server's hostname-to-IP address cache or
    5·1 answer
  • Which principle of design does a designer apply when they create rhythmic movement in a garment by using recurring pleats or det
    13·1 answer
  • Given the statement: int list[25]; The index can go from 0 to 25 inclusive withoutgoing beyond the end of the array.true or fals
    14·1 answer
  • Group of answer choices When declaring a variable, you also specify the type of its values. Variables cannot be assigned and dec
    7·1 answer
  • In confirmatory visualization Group of answer choices Users expect to see a certain pattern in the data Users confirm the qualit
    9·1 answer
  • What are the five Ws?<br> (I don’t even know what this means)
    5·2 answers
  • ___ is a form of electronic money that is decentralized and whose transactions are encrypted, processed, and recorded via peer-t
    10·2 answers
  • Giving brainliest to the Person finishes this song lyric.
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!