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
AfilCa [17]
4 years ago
8

You are given an unsorted array x of elements that implement the Comparable interface. There are no duplicates in this array. Yo

u are also given a variable m of type Comparable. Write the code needed to assign to m a reference to the median value of the array. (You may modify the array x by rearranging its elements.)NOTE: The median of a set of values is the value in the set such that there are as many values that are greater as there are that are less. For purposes of THIS exercise, if the array has an even number of members, the median is the greater of the two middle values.
EXAMPLE 1: Given "bob" "carol" "ted" "alice" "fred" the median is "carol" because there are "bob" and "alice" are less than "carol" and "fred" and "ted" are greater.
EXAMPLE 2: Given "bob" "carol" "ted" "alice" "fred" "sue", the middle two values are "carol" and "fred" and so in THIS exercise we would consider the greater to be the median.
Computers and Technology
1 answer:
Andrei [34K]4 years ago
8 0

Answer:

boolean isEven = false;

if (x.length % 2 == 0)

isEven = true;

Comparable currentMax;

int currentMaxIndex;

for (int i = x.length - 1; i >= 1; i--)

{

currentMax = x[i];

currentMaxIndex = i;

for (int j = i - 1; j >= 0; j--)

{

if (((Comparable)currentMax).compareTo(x[j]) < 0)

{

currentMax = x[j];

currentMaxIndex = j;

}

}

x[currentMaxIndex] = x[i];

x[i] = currentMax;

}

Comparable a = null;

Comparable b = null;

if (isEven == true)

{

a = x[x.length/2];

b = x[(x.length/2) - 1];

if ((a).compareTo(b) > 0)

m = a;

else

m = b;

}

else

m = x[x.length/2];

You might be interested in
Which UPPER function is written so that all text in cell B4 will be capitalized? O=UPPER(B4) O=UPPER[B4] O UPPER B4 O=UPPER
Irina-Kira [14]
The Excel UPPER function converts a text string to all uppercase letters. Numbers, punctuation, and spaces are not affected.

So , Which upper function is written so that all text in cell b4 will be capitalized

Answer is : PROPER function
3 0
2 years ago
____ are the computers that store network software and shared or private user files.
kodGreya [7K]
Servers <span>are the computers that store network software and shared or private user files.</span>
3 0
4 years ago
What is a moves track
saveliy_v [14]
It is an activity diary
8 0
4 years ago
A programming and software development professional would most likely help with
DiKsa [7]
A programming and software development professional would most likely help with
Testing a software program.
3 0
3 years ago
Attetion developers i have a question can u devlop a website
Eva8 [605]
Yes, you can, with certain apps or with websites. Try Mozilla Web Maker.
3 0
3 years ago
Read 2 more answers
Other questions:
  • How can social media be used in "child-driven" education? What benefits can students around the world gain from social media?
    12·1 answer
  • write an algorithm that gets the price for item A plus the quantity purchased. The algorithm prints the total cost, including a
    5·1 answer
  • At the top level of a tree is a single node called the ________ a)pinnacle b) root c) top d)front
    12·1 answer
  • A polyalphabetic cipher uses many ___
    6·1 answer
  • A website that sells high-end ties notices that its ads are showing up for searches that include "cheap". Because its ties are e
    14·1 answer
  • Select the correct answer.
    10·2 answers
  • George enters the types of gases and the amount of gases emitted in two columns of an Excel sheet. Based on this data he creates
    6·1 answer
  • What is the difference btween a microcontroller a mini computer?
    15·2 answers
  • Which option correctly identifies if the researcher’s approach was the best start in the following scenario and explains why?
    10·2 answers
  • In the chemical reaction of baking cookies, the product is?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!