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
Can someone please help???
Ksivusya [100]

Answer:

Look it up

Explanation:

You don’t need to buy another

8 0
2 years ago
Explain why cloud computing can be more complex than a traditional approach.
sp2606 [1]

Cloud computing is more complex than traditional approach due to the following reasons.

Explanation:

1.Cost Savings and Total Cost of Ownership. When you move to cloud computing you tend to save money in several ways in comparison to traditional IT, including the reduction of in-house equipment and infrastructure.

2.Dissatisfaction in Traditional IT. Many companies are frustrated with the negatives that come with traditional IT, such as poor data backup, managing and maintaining your own hardware, and lack of disaster recovery options.

3.Time to Value and Ease of Implementation. Since you don’t have to spend time configuring hardware, maintain systems, and patching software, you can invest your resources elsewhere.

4.Access to Emerging Technology. Much like a car, the minute you purchase on-premise hardware and software, it immediately starts to age. You can access the latest and greatest innovations with a cloud provider who has more purchasing power and stays up-to-date with available solutions. Also, as new innovations are released, they become less likely to integrate with legacy solutions that are often inflexible. Instead, cloud-first development is coming to the forefront.

5.Using Hybrid to Optimize your Operations. Some organizations take the use of the cloud even further by using multiple clouds simultaneously, thus giving them even more agility. Workloads are placed where they perform best, and where costs are most efficient.

5 0
3 years ago
The number of colors available in a graphic is referred to as......what?
polet [3.4K]

<span>The number of colors available in a graphic is referred to as color depth. Color depth is also known as bit depth. It is the number of bits used to indicate the color of a single pixel, in a bitmapped image or video frame buffer or the number of bits used for each color component of single pixel.</span>

4 0
3 years ago
What princple of animation is used to animate the movements of the arms of the following character while walking?
Gala2k [10]

Answer:

arc

Explanation:

4 0
3 years ago
Assume the existence of a BankAccount class with a method, getAvailable that returns the amount of available funds in the accoun
julia-pushkina [17]

Answer: This is hard but I will research ok

Explanation:

6 0
3 years ago
Other questions:
  • The term ________________ denotes data that is being stored on devices like a universal serial bus (USB) thumb drive, laptop, se
    9·2 answers
  • Binary code what does this mean I was sick so I don't under stand
    7·2 answers
  • Describe FIVE significant advantages of web-based applications for an organisation.
    7·1 answer
  • _____ consists of the instructions that direct the operation of the computer system and enable users to perform specific tasks,
    15·1 answer
  • write a program with total change amount as an integer input and output the change using the fewest coins, one coin type per lin
    8·1 answer
  • What is known as networking in the IT field?
    8·1 answer
  • Technology has had
    10·1 answer
  • Overview In this assignment, you will gain more practice with designing a program. Specifically, you will create pseudocode for
    7·1 answer
  • ¿Por qué disminuyó el tamaño de la población de caribús? Usa la evidencia inicial para explicar por qué disminuyó el tamaño de l
    5·1 answer
  • Many phone fraud scammers are expessily cunning because they approach the target to try to sell
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!