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 8895145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:41:56+00:00 2026-06-14T23:41:56+00:00

I am trying to code quicksort in two ways, one in-place, and the other

  • 0

I am trying to code quicksort in two ways, one in-place, and the other by using separate arrays. I’m kind of stuck on some of the logic, take a look at what I have, Thanks for the help in advance!

public List<Integer> sort(List<Integer> arr){
  if(arr.length > 0)
    List<Integer> ret = new ArrayList<Integer>();
  ret = quickSort(arr);
  return ret;
 }

public List<Integer> quickSort(List<Integer> arr){
  if(arr.length < 2)
    return;

  int pivot = arr[0];
  List<Integer> left = new ArrayList<Integer>();
  List<Integer> right = new ArrayList<Integer>();

  for(int i = 0; i < arr.length; i++){
    if(arr[i] <= pivot)
      left.add(arr[i]);
    else
      right.add(arr[i]);
  }
  quickSort(left);
  quickSort(right);

}

Now i’m stuck, I don’t know what I would do after recursively going through both sets, mostly stuck on how would I connect them together and return a sorted list.

  • 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-06-14T23:41:58+00:00Added an answer on June 14, 2026 at 11:41 pm

    You need to combine left and right sequences together. You need to do it at the end of your algorithm (before the closing }). In pseudo code:

    int leftpos = 0, rightpos = 0;
    List newlist = new ArrayList();
    for(int pos = 0; pos < arr.length; pos++)
      if left[pos] < right[pos] newlist.add(left[leftpos++]);
        else newlist.add(right[rightpos++]);
    return newlist;
    

    This is just a pseudo-code. You need to add code to check lengths of each array (left and right) in the for cycle.

    Also I must note that this is far from quicksort. So many new array allocations make the algorithm extremely slow and that’s unwelcome when sorting.

    Also, right side of line 3 is redundant. You don’t need to allocate anything here, as it is overwritten in the next line. I would just simply replace your lines 3-5 with this:

    return quickSort(arr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to code a popup but I ran into some problems when using
i'm trying to profile a quicksort code. the code is as follows: qsort []
I am trying to code AES using Cipher Block Chaining(CBC) mode. I am pretty
I am trying to code the following query using Zend_Db api's: select * from
I'm trying to implement quicksort in a functional style using C# using linq, and
I'm having some problems with the stack in java... I'm implementing quicksort using an
What's up y'all, I am trying to write some code in Java that will
While trying to port some code to compile in linux I get peculiar compilation
I am trying to clean up some existing code Sheets(Control).Select MyDir = Cells(2, 1)
I'm trying to code a python google api. Getting some unicode issues. My really

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.