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

  • Home
  • SEARCH
  • 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 8006577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:33:29+00:00 2026-06-04T17:33:29+00:00

I am having trouble with converting my sorting class to sort objects with arraylists.

  • 0

I am having trouble with converting my sorting class to sort objects with arraylists. It is currently sorting objects, but I am having trouble converting it to sorting Arraylists. Here is the code:

package Merge_Sort_Objects_ArrayList;
import java.util.ArrayList;
public class mergesort {

    /**
     * Merges two sorted portion of items array
     * pre: items[start.mid] is sorted.  items[mid+1.end] sorted.  start <= mid <= end
     * post: items[start.end] is sorted
     */

    private static void merge(ArrayList <Comparable> items, int start, int mid, int end){
            Comparable temp;
            int pos1 = start;
            int pos2 = mid + 1;
            int spot = start;
            ArrayList <Comparable> objectSort = items;

            while (!(pos1 > mid && pos2 > end)){
                if ((pos1 > mid) || ((pos2 <= end) &&(items[pos2].getRadius() < items[pos1].getRadius()))){
                    temp[spot] = items[pos2];
                    pos2 +=1;
                }else{
                    temp[spot] = items[pos1];
                    pos1 += 1;
                }
                spot += 1;
            }
            /* copy values from temp back to items */

            for (int i = start;  i <= end; i++){
                items[i] = temp[i];
            }
    }

    /**
     * mergesort items[start..end]
     * pre: start > 0, end > 0
     * post: items[start..end] is sorted low to high
     */
    public static void mergesort(ArrayList <Comparable> items, int start, int end){
        if (start < end){
            int mid = (start + end) / 2;
            mergesort(items, start, mid);
            mergesort(items, mid + 1, end);
            merge(items, start, mid, end);
        }
    }
}

now I have started to convert it, however I am stuck on this section right here:

  while (!(pos1 > mid && pos2 > end)){
            if ((pos1 > mid) || ((pos2 <= end) &&(items[pos2].getRadius() < items[pos1].getRadius()))){
                temp[spot] = items[pos2];
                pos2 +=1;
            }else{
                temp[spot] = items[pos1];
                pos1 += 1;
            }
            spot += 1;
        }
        /* copy values from temp back to items */

        for (int i = start;  i <= end; i++){
            items[i] = temp[i];
        }

Thank you in advance!

  • 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-04T17:33:30+00:00Added an answer on June 4, 2026 at 5:33 pm

    Use the fact that

    Foo[] array = ......;
    Foo rhs = .....;
    Foo lhs;
    array[i] = rhs;
    lhs = array[j];
    

    is analogous to:

    ArrayList<Foo> list = .....;
    Foo rhs = ......;
    Foo lhs;
    list.set(i, rhs);
    lhs = list.get(i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made my first class and I'm having trouble converting the objects back into
I'm trying to implement picking using Pyglet's OpenGL wrapper, but I'm having trouble converting
I'm having some trouble converting a parameter: I have this structure: class XMLCO {...};
I'm having trouble converting this piece of code (originally in VB) to C#. In
I am having trouble converting some code from VB6 to VB.NET (I don't have
I am having trouble converting this code into extension method syntax: var query =
I've been having trouble converting the following fairly straight forward c# code into vb.net
I'm having trouble converting especially the getter and setter. public class CartItem : IEquatable<CartItem>
I'm having trouble converting objects into JSONObject (org.json.JSONObject) in java. I have an object
Having trouble converting the following code from dealing with IDs to Classes. Basicly what

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.