Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6808921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:00:57+00:00 2026-05-26T20:00:57+00:00

I need to create a random array of int and have it sorted by

  • 0

I need to create a random array of int and have it sorted by my own class. Here is where I make my array:

public class MyProgram9{
 public static void main(String[] args){

    int[] list = new int[10];
    for (int i=0; i<10; i++){
        int n = (int)(Math.random()*9 + 1);
        list[i] = n;

        System.out.println(list[i] + " ");
    }
    list.QuickSort();
 }
}

I then am trying to use another class to sort it(the QuickSort class). My Question is how do I implement this class from the same folder so that I can use it. Here is the quickSort class:

public class QuickSort{
public static void quickSort(int[] list){
quickSort(list, 0, list.length - 1);
  }

private static void quickSort(int[] list, int first, int last) {
if (last > first) {
  int pivotIndex = partition(list, first, last);
  quickSort(list, first, pivotIndex - 1);
  quickSort(list, pivotIndex + 1, last);
}
 }

 /** Partition the array list[first..last] */
 private static int partition(int[] list, int first, int last) {
int pivot = list[first]; // Choose the first element as the pivot
int low = first + 1; // Index for forward search
int high = last; // Index for backward search

while (high > low) {
  // Search forward from left
  while (low <= high && list[low] <= pivot)
    low++;

  // Search backward from right
  while (low <= high && list[high] > pivot)
    high--;

  // Swap two elements in the list
  if (high > low) {
    int temp = list[high];
    list[high] = list[low];
    list[low] = temp;
  }
}

while (high > first && list[high] >= pivot)
  high--;

// Swap pivot with list[high]
if (pivot > list[high]) {
  list[first] = list[high];
  list[high] = pivot;
  return high;
}
else {
  return first;
   }
  }
}

Sorry about all the info.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:00:57+00:00Added an answer on May 26, 2026 at 8:00 pm

    If you mean how to connect the two classes your code is wrong. You have to call the static quicksort method on the array. Like:

    public class MyProgram9{
     public static void main(String[] args){
    
        int[] list = new int[10];
        for (int i=0; i<10; i++){
            int n = (int)(Math.random()*9 + 1);
            list[i] = n;
    
            System.out.println(list[i] + " ");
        }
        QuickSort.quicksort(list);
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why do i need to create an instance of Random class, if i want
how make special random array. i have array(1=>35,2=>25,3=>40) . how make possibility that array
I need to create an array of arrays int x[][] = new int[20][3]; where
I have scipy and numpy, Python v3.1 I need to create a 1D array
I need to create an NSString that has a single random uppercase letter. I
In my constructor, I want to create a random color. Therefore, I need three
I need help with writing some code that will create a random number from
I have a comma separated string, out of which I need to create a
I need to create random numbers between 0 and upto 2 so I am
I have an array of double values vals, I need to randomly index into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.