IntellTanito
19.05.2021 •
Computers and Technology
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() {...}
Solved
Show answers
More tips
- S Style and Beauty How to Braid Hair with a Plaiting Machine: Tips and Recommendations...
- B Business and Finance How to Create a Business Plan? Your Ultimate Guide...
- F Food and Cooking Deflope: What is it and how does it work?...
- F Food and Cooking Why Doesn t the Confirmation Link Come to Email?...
- F Food and Cooking How to Get Reconfirmation of Registration?...
- S Science and Technology Discovering the Anatomy of an LCD TV Screen...
- H Health and Medicine What You Need to Know About Nasal Congestion in Infants: Causes, Symptoms, and Treatment...
- A Auto and Moto What is the Average Lifespan of an Engine in a Car?...
- C Computers and Internet Make Money Online: Secrets and Essential Ways...
- A Auto and Moto How Can Parking Sensors Help Drivers?...
Answers on questions: Computers and Technology
- C Computers and Technology Can you hear the silence? can you see the dark? can you fix the broken? can you feel... CAN YOU FEEL MY HEAR...
- B Biology What are the two main classification of ecosystems? a.biotic abiotic b. terrestrial and aquatic c. closed and open d. inputs and outputs...
- M Mathematics What is the first step in deciding whether the relationship between the number of yards and the hours spent raking is proportional? Think About the Process Zach ears extra...
- B Business A 1,000 square foot office space is leased at $20.00 per square foot during the first year with $2.00 step-up provisions each of the following years. The lease is gross with...
- H History How do the distribution gains differ from 1946-1976, 1976-2006?...
- E English What are your thoughts...
Ответ:
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.Ответ:
I do
Explanation:
If you mark brainliest we can have lots of fun