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
Y_Kistochka [10]
3 years ago
5

Write a function findEvenQueue that returns the first even number in the Queue. The function looks at the value at the front of

the queue and checks if it’s even. If the value is even, then it returns that number. If the value is not even, then it removes that item from the queue and the process is repeated checking the front of the queue again. The function should return -1 if there are no even numbers. HINT: The program should make use of the peek method and the poll method of the queue.
Computers and Technology
1 answer:
Bumek [7]3 years ago
4 0

Answer:

Check the explanation

Explanation:

CODE:

static int findEvenQueue(Queue<Integer> numbers)

{

//loop runs till the queue has atleast one element

while(numbers.size() > 0)

{

//Checking the head of the queue whether it is even

int temp = numbers.peek();

if(temp % 2 == 0)

{

//if the head is even then return it

return temp;

}

else

{

//else remove the number at head

int removed = numbers.poll();

}

}

//if no even number present in the Queue then return -1

return -1;

}

You might be interested in
Which of the following computer component facilitates internet connection?
babunello [35]

Answer:

your answer may be(utility software)

8 0
3 years ago
Read 2 more answers
Write a function that takes a string like 'one five two' and returns the corresponding integer (in this case, 152). A function j
Lelu [443]

Answer:

see explaination

Explanation:

def words2number(s):

words = s.split()

numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']

result = ""

for word in words:

if word in numbers:

result += str(numbers.index(word))

return result

4 0
4 years ago
Read 2 more answers
What is true about an electric field around a negative charge?
FrozenT [24]

The electric field points outward

8 0
3 years ago
Read 2 more answers
Suppose that the splits at every level of quicksort are in the proportion 1 − α to α where 0 &lt; α ≤ 1/2 is a constant. Show th
Lady_Fox [76]

Answer:

Explanation:

The minimum depth occurs for the path that always takes the smaller portion of the

split, i.e., the nodes that takes α proportion of work from the parent node. The first

node in the path(after the root) gets α proportion of the work(the size of data

processed by this node is αn), the second one get (2)

so on. The recursion bottoms

out when the size of data becomes 1. Assume the recursion ends at level h, we have

(ℎ) = 1

h = log 1/ = lg(1/)/ lg = − lg / lg

Maximum depth m is similar with minimum depth

(1 − )() = 1

m = log1− 1/ = lg(1/)/ lg(1 − ) = − lg / lg(1 − )

4 0
4 years ago
Is C++ a high-level or low-level programming language? What about HTML?
N76 [4]

Answer:

c++ is low level

html high level

Explanation:

6 0
3 years ago
Other questions:
  • If Mark is developing a website to be optimized for mobile devices, what would be the top-level domain?
    10·1 answer
  • Fullsoft, Inc. is a software development company based in New York City. Fullsoft’s software product development code is kept co
    10·1 answer
  • Put the following five steps in the order in which you would perform them to use the Paste Special function. 1. Select and copy
    6·1 answer
  • Difference between volatile and non volatile memory
    14·2 answers
  • list = 7 # these many modified Fibonacci numbers. def fibonacci_gt(n, t1, t2): if n&lt;0: print("Incorrect input") elif n == 0:
    12·1 answer
  • Write a program called array1.cpp file that use either regular for loop or range based for loop to display the contents of the a
    14·1 answer
  • Which tool can be used to increase the space between a bullet point or a number and text?
    11·2 answers
  • How can Technology be used in marketing?
    5·1 answer
  • I need advice, please try to give a full paragraph and include a p r o s and c o n s list, no l i n k s please, it would mean so
    8·1 answer
  • Explain the working principal of computer system with suitable diagarm​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!