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
dybincka [34]
3 years ago
13

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. You will probably want to review the array partitioning algorithm presented in class. Note that we are asking you to partition based on the last value in the array, rather than the first. However, you can address this difference with a small adjustment before you begin.
Computers and Technology
1 answer:
Nuetrik [128]3 years ago
8 0

Answer:

Check the explanation

Explanation:

class Partioner {

   public static int partition(int[] values) {

       if (values == null || values.length < 1)

           return 0;

       // getting pivot value

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

       // pivot index

       int pivot_index = values.length - 1;

       // looping through values

       for (int i = values.length - 2; i >= 0; i--) {

         

           if (values[i] == pivot) {

               pivot_index--;

               continue;

           }

            // if immediate number is greater than pivot

           if (values[i] > pivot) {

               if (pivot_index - i == 1) {

                   int temp = values[i];

                   values[i] = pivot;

                   values[pivot_index] = temp;

                   pivot_index--;

               } else {

                   int temp = values[i];

                   values[i] = values[pivot_index - 1];

                   values[pivot_index - 1] = temp;

                   temp = values[pivot_index - 1];

                   values[pivot_index] = temp;

                   values[pivot_index - 1] = pivot;

                   pivot_index--;

               }

           }

       }

       // returning pivot index

       return pivot_index;

   }

   // testing the function

   public static void main(String[] args) {

       int values[] = { 11, 9, 2, 7, 21, 6, 10, 10, 10 };

       System.out.println("pivot index : " + Partioner.partition(values));

       System.out.println();

   }

}

// OUTPUT

pivot index : 4

You might be interested in
___ Jacking is a crime that takes place when a hacker misdirects URL to a different site. The Link Itself Looks Safe, But the us
const2013 [10]

Answer: Web Jacking

Here, the hacker takes control of a web site fraudulently. He may change the content of the original site or even redirect the user to another fake similar looking page controlled by him.


If you have any other questions about computers or even hacking hit me up because I know a lot about computers

6 0
3 years ago
What is the best data structure to solve the following problem? a) A list needs to be built dynamically. b) Data must be easy to
LekaFEV [45]

Data must be easy to find, preferably in O(1) is the best data structure to solve the following problem.

b) Data must be easy to find, preferably in O(1).

<u>Explanation:</u>

The best data structure should covers, linked list, arrays, stack, queues, tree, graphics extra. Data structure stores the data either ascending order or descending order. Since it has linked list to store values.  

If the data structure  display starts  will store or displayed from ascending order to ascending order, when it starts from left to right.

If the data structure display starts will store or displayed from descending order to descending  order when it starts from right to left data value.

Searching the value in the data structure should be easy.

8 0
3 years ago
What are 3 important reasons to reconcile bank and credit card accounts at set dates?
Karo-lina-s [1.5K]

Answer:

To verify transactions have the correct date assigned to them.

To verify that an account balance is within its credit limit.

To verify that all transactions have been recorded for the period.

Explanation:

7 0
3 years ago
The benefits associated with software reuse are lower cost, better quality,
Sholpan [36]

Answer:

Software reuse is the technique through which updating the software system through the already defined components or assets of the software.This helps in increasing the productivity ,cost decrement , quality improvement etc.

But in actual case, the software reuse still persist high cost due to modification of inflexible designing of software .It also costs more than expected for the maintenance and training of software.

The security of the software is always at risk because of the usual and advanced hacking and attacking by the hackers even when the protect of software is high.Thus, these statements verify that the benefits of cost and security of software is not actually realized.

6 0
3 years ago
Your sister has just emailed you an attached file with the invitation list for her upcoming party.
Andreyy89

Answer:

The file Extension so the answer is C

5 0
2 years ago
Read 2 more answers
Other questions:
  • Where does the VLookup function find its lookup values?
    14·1 answer
  • Max needs to study more effectively to get a better grade on his next exam. What can he do to improve his study habits? Check al
    10·2 answers
  • Which of the following can be considered beta testing? A programmer at Linus Systems checks the integration of multiple modules
    14·1 answer
  • What typed of google group is best-suited for an online study group?
    7·1 answer
  • What do you think is the biggest threat to the security of your personal information?
    5·2 answers
  • The following program is run. Then the user clicks the "bottomButton" TWO TIMES. What will be displayed in the console?
    6·2 answers
  • Which 2 processes are operational processes
    10·1 answer
  • It is a kind of malware (malicious software) that criminals install on your computer so they can lock it from a remote location.
    15·2 answers
  • 4. Each mobile device described in this chapter requires that the user have a/an ____________________ associated with services o
    5·1 answer
  • The lost boy gave the correct
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!