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
solmaris [256]
3 years ago
8

Suppose that you are asked to modify the Stack class to add a new operation max() that returns the current maximum of the stack

comparable objects. Assume that pop and push operations are currently implemented using array a as follows, where item is a String and n is the size of the stack. Note: if x andy are objects of the same type, use x.compareTo(y) to compare the objects x and y public void push String item ) { [n++] = iten; } public String pop { return al--n]; } Implement the max operation in two ways, by writing a new method using array a (in 8.1), or updating push and pop methods to track max as the stack is changed (in 8.2). Q8.1 Implement method maxi 5 Points Write a method max() using Out) space and Oin) running time. public String max() {...} Enter your answer here Q8.2 Update push() and popo 5 Points Write a method max() using On) space and 011) run time. You may update the push and pop methods as needed public void push {...} public String pop() {...} public String max() {...}
Computers and Technology
1 answer:
Advocard [28]3 years ago
7 0

Answer:

Following are the code to the given points:

Explanation:

For point 8.1:

public String max()//defining a method max

{

   String maxVal=null;//defining a string variable that holds a value

   for(int x=0;x<n;x++)

   {

       if(maxVal==null || a[i].compareTo(maxVal)>0)//defining if blok to comare the value

       {

           maxVal=a[i];//holding value in maxVal variable

       }

   }

   return maxVal;//return maxVal variable value

}

For point 8.2:

public void push(String item)//defining a method push that accepts item value in a parameter

{

       a[n]=item;//defining an array to hold item value

       if(n==0 || item.compareTo(maxVals[n-1])>0)//use if to comare item value

       {

               maxVals[n]=item;//holding item value in maxVals variable

       }

       else

       {

               maxVals[n]=maxVals[n-1];//decreasing the maxVals value

       }

       n++;//incrementing n value

}

public String pop()//defining a method pop

{

       return a[--n];//use return value

}

public String max()//defining a method max

{

       return maxVals[n-1];//return max value

}

  • In the first point, the max method is declared that compares the string and returns its max value.
  • In the second point, the push, pop, and max method are declared that works with their respective names like insert, remove and find max and after that, they return its value.
You might be interested in
If the algorithm does not have instructions for unanticipated results, the computer program will a. solve a problem b. start ove
MrMuchimi

Answer: halt, just did the question

6 0
3 years ago
What kind of company would hire an Information Support and Service employee?
Murrr4er [49]

Answer:

B. Computer Repair

Explanation:

I got it right on edge. trust.

7 0
2 years ago
Read 2 more answers
Which best describes obliteration in a forged document?
Drupady [299]
The answer is B bc obliteration is related to covering the document
4 0
3 years ago
Which scenario is most likely due to an everyday problem rather than a
tester [92]

The scenario is most likely due to an everyday problem rather than cultural difference among people collaborating online is option D. A team member's bandwidth is limited, and the video feed keeps freezing.

<h3>What is collaborating online?</h3>

Online collaboration is known to be a term that connote the use the internet as well as other forms of online tools to be able to work together on some work or project.

Note that it is one that is done Instead of a person sitting in a physical office space, the online collaboration gives room for employees to be able to work together from different locations and tech by accessing the virtual work environments as well as other shared online workspaces.

Therefore, The scenario is most likely due to an everyday problem rather than cultural difference among people collaborating online is option D. A team member's bandwidth is limited, and the video feed keeps freezing.

Learn more about collaborating online from

brainly.com/question/514815

#SPJ1

6 0
1 year ago
Both UDP and TCP use port numbers to identify the destination entity when delivering a message. Give at least one reason for why
raketka [301]

Answer:

Follows are the solution to this question:

Explanation:

The process ID is not static because this can't be used to identity, therefore, it includes excellent service providers like HTTP since it is allocated dynamically only to process whenever a process is initiated.

Sometimes its instance connectors are managed on numerous TSAPs. This can be implemented unless the process ID is being used as each procedure could have an identity.

4 0
2 years ago
Other questions:
  • A network administrator is implementing dhcpv6 for the company. the administrator configures a router to send ra messages with m
    6·1 answer
  • What is a block cipher algorithm that operates on 64-bit blocks and can have a key length from 32 to 448 bits?
    8·1 answer
  • We must know the Inflation Rate and the Nominal GDP in order to calculate Real GDP.
    15·1 answer
  • Which tab is used to edit objects on the slide master and layouts
    10·1 answer
  • There are a few simple rules that you can follow to store and manage files and folders in your computer. What is the most import
    9·2 answers
  • PreparedStatement ps = connection.prepareStatement("select firstName, mi, lastName from Student where lastName = ?"; ps.setStrin
    5·1 answer
  • Henry, a graphic artist, wants to create posters. Which software should Henry use for this purpose?
    13·1 answer
  • Of all excavation hazards, _______ poses the greatest risk
    8·1 answer
  • Write a program, named NumDaysLastNameFirstName.java, which prompts the user to enter a number for the month and a number for th
    13·1 answer
  • 1. The running configuration is also known as the _____________ (Select Two) a. Startup config b. Working configuration c. Curre
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!