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
An operator can be overloaded to define functionality that is drastically different from the original operator.
zvonat [6]
A. True

Explanations:

You can redefine or overload the function of most built-in operators in C++. These operators can be overloaded globally or on a class-by-class basis. Overloaded operators are implemented as functions and can be member functions or global functions. An overloaded operator is called an operator function.
5 0
2 years ago
What does the acronym API stand for?
lozanna [386]

Answer: D) Application programming interface

It's like a layer that is between the programmer/program and the hardware. It allows developers to create useful programs or tools for operating systems.

8 0
4 years ago
Read 2 more answers
A network administrator is planning redundant devices and cabling in a switched network to support high availability. Which bene
a_sh-v [17]

Answer:

Redundant paths can be available without causing logical Layer 2 loops.

Explanation:

  • Spanning Tree Protocol is used to allow redundancy in the Layer 2 switched networks without creating cycles/circles also called loops.
  • These loops are called physical loops.
  • When two parts of the switched network are connected via two or more Layer 2 switches this result in a loop.
  • This affects the performance of the network as the result of broadcast packets flooding.
  • STP puts one port of the switch to forward mode and the rest of the ports within the same part of the network to the blocking mode to avoid broadcast packet flooding. STP puts all the ports that are allowing redundant paths to block mode and the one port that is left after this is placed in forward mode.
  • Spanning Tree Algorithm is used by STP to determine the optimal path  of switch to the network.
  • Bridge Protocol Data Units are used to share the information about the optimal path determined by the spanning tree algorithm with other switches.
  • This information helps STP to eliminate the redundant paths.
  • So this is how STP tracks all the links in the switched network and eliminates redundant loops by allowing only one active path to the destination while blocking all other paths.
7 0
3 years ago
All jobs that involve the web require a computer science degree true or false
Ipatiy [6.2K]

So I'd say false, I don't think that it's required to have a computer science degree but getting hired as a programmer without a computer science degree takes some work.

Please correct me if I'm wrong!! I'd be happy to fix it!! :)

7 0
3 years ago
Read 2 more answers
NEED HELP WILL MARK BRAINLIEST 25 POINTS FOR ANSWER
Nataly [62]

Answer:

relationship

Explanation:

7 0
3 years ago
Read 2 more answers
Other questions:
  • Explain the theory of electro-magnetism
    8·1 answer
  • Francis works in the human resources division of a large oil and gas company in Texas. Francis' tasks include maintaining payrol
    14·1 answer
  • Which best describes IMEI?
    7·1 answer
  • Write a loop statement to count and display the number of positive integers in the array. That is, your loop should display the
    14·1 answer
  • How many four-digit personal identification numbers (PIN) are possible if the PIN cannot begin or end with a 0 and the PIN must
    6·1 answer
  • How many Iron molecules are in the compound Fe4O2?
    15·2 answers
  • This function whose primary purpose is to display information to the user can only display one value at a time.
    15·1 answer
  • A device that allows multiple computers to communicate with each other is
    9·1 answer
  • Which position most likely requires your Master's Degree for success
    7·1 answer
  • Yo, my Lenovo laptop keeps showing this screen but I can't sign in, can someone help me?
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!