(Solved) : Wrong Following Code Piece Code Incorrectly Attempts Find Largest Value Queue Integers Wou Q42703229 . . .

  1. What is wrong with the following code? This piece of codeincorrectly attempts to find the largest value in a queue ofintegers. How would you fix it? You will need to write a class withthe main(String[] args) {….} method to test the following piece ofcode, find the problem, and fix it.

          intlargest = q.remove(); //assume the first one is the largest.

                for(inti=0; i <q.size(); i++){

                       largest =Math.max(largest,q.remove());

                }

There are many waysto find the maxi value from a queue list. For this problem, you arenot allowed to use any collection utilities; you will have to usethe Math.max( largest, q.remove( )) method and you cannot modifythe original queue contents. For example, with my queue list (1, 2,3, 99, -4, 6), the results should look like the following.

Orginal list

[1, 2, 3, 99, -4,6]

largest = 99

After finding maxi,the list is

[1, 2, 3, 99, -4,6]

Expert Answer


Answer to What is wrong with the following code? This piece of code incorrectly attempts to find the largest value in a queue of …

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?