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
a_sh-v [17]
4 years ago
3

Create a public non-final class named Partitioner. Implement a public static method int partition(int[] values) that returns the

input array of ints partitioned using the last array value as the pivot. All values smaller than the pivot should precede it in the array, and all values larger than or equal to should follow it. Your function should return the position of the pivot value. If the array is null or empty you should return 0.
Computers and Technology
1 answer:
STALIN [3.7K]4 years ago
7 0

Answer:

See Explaination

Explanation:

public class Partitioner {

public static int partition(int[] values){

if(values==null || values.length==0)return 0;

// storing the pivot value

int pivot = values[values.length-1];

//sorting the array

for(int i=0;i<values.length-1;i++){

int m_index = i;

for (int j=i+1;j<values.length;j++)

if(values[j]<values[m_index])

m_index = j;

int tmp = values[m_index];

values[m_index] = values[i];

values[i] = tmp;

}

int i = 0;

// first finding the index of pivot

// value in sorted order and recording index in i

while (i<values.length){

if(pivot==values[i]){

if(i==values.length-1)break;

int j=0;

// finding the location for inserting the

while (j<values.length){

if(pivot<=values[j]){

// inserting the values

values[i] = values[j];

values[j] = pivot;

break;

}

j++;

}

break;

}

i++;

}

return i;

}

// main method for testing can be removable

public static void main(String[] args) {

int a[] = {4,1,6,2};

System.out.println(partition(a));

}// end of main

}

You might be interested in
Output: Your goal
Sonja [21]

Answer:

1 n-var When you make a comparison, you consider two or more things and discover the differences between them. oft N of/between pl-n.

4 0
3 years ago
Choose the 3 Points in good story telling
Sidana [21]

Answer:

1.Choose a clear central message 2. Embrace conflict 3.Have a clear structure  

Explanation:

8 0
2 years ago
A _____ is the useful part of a transmission through a network.
Crazy boy [7]

Answer: LAN

Explanation:

3 0
3 years ago
___________________ has made the education process more effective and productive.
OlgaM077 [116]

I'm thinking <u>technology</u> maybe?

4 0
2 years ago
Read 2 more answers
Express the worst case run time of these pseudo-code functions as summations. You do not need to simplify the summations. a) fun
ser-zykov [4K]

Answer:

The answer is "O(n2)"

Explanation:

The worst case is the method that requires so many steps if possible with compiled code sized n. It means the case is also the feature, that achieves an average amount of steps in n component entry information.

  • In the given code, The total of n integers lists is O(n), which is used in finding complexity.
  • Therefore, O(n)+O(n-1)+ .... +O(1)=O(n2) will also be a general complexity throughout the search and deletion of n minimum elements from the list.
5 0
3 years ago
Other questions:
  • . When you have multiple graphics positioned on a page, you can _______________ them so that they are a single graphic instead o
    9·1 answer
  • Some projectors use a connection technology called _______________ that enables long-range connectivity for uncompressed HD vide
    7·1 answer
  • PLEASE HELP!!!!!!!!!!!
    15·2 answers
  • Consider the following code which deletes all the nodes in a linked list. void doublyLinkedList::destroy() { nodeType *temp; //p
    14·1 answer
  • What year did Elvis die? Right answer 1977.
    14·1 answer
  • Which memory device is most appropriate for backing up a computer’s hard drive?
    11·2 answers
  • A location in space is called?
    6·2 answers
  • Write a method, including the method header, that will receive an array of integers and will return the average of all the integ
    7·1 answer
  • What three actions happen when you cloak a folder or file?
    6·1 answer
  • When using a self-contained recovery device on a cfc, hcfc, or hfc system with an operating compressor, technicians must?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!