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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:06:57+00:00 2026-06-16T23:06:57+00:00

This is a program that using merge sort – sorts a list of 1000

  • 0

This is a program that using merge sort – sorts a list of 1000 numbers from 1 – 1000.
It displays the original list, then calls a recursive method to sort it, then displays it.

What I do not understand within the code are these two lines:

MergeSort (numbers, low, middle); // within method it will say "HERE"

MergeSort (numbers, middle + 1, high);

I am a beginner in java and this goes against everything I learned as I cant comprehend how you can call a method within a method. Unless its a object whcih I doubt. Could someone explain me what these two lines of code do?

import java.io.*;
import java.util.*;
import java.text.*;

public class MergeSortExample
{
    static final int Max = 1000;

    static void MergeSort (int[] numbers, int lo, int n) // recursive method
    {

        int low = lo; // 0
        int high = n; // 999

        if (low >= high) // return case;
        {
            return;
        }

        int middle = (low + high) / 2;
        MergeSort (numbers, low, middle); // HERE
        MergeSort (numbers, middle + 1, high); // HERE

        int end_low = middle;
        int start_high = middle + 1;

        while ((lo <= end_low) && (start_high <= high))
        {
            if (numbers [low] < numbers [start_high])
            {
                low++;
            }
            else
            {
                int Temp = numbers [start_high];

                for (int k = start_high - 1 ; k >= low ; k--)
                {
                    numbers [k + 1] = numbers [k];
                }
                numbers [low] = Temp;
                low++;
                end_low++;
                start_high++;
            }
        }




    }


    public static void main (String str[]) throws IOException
    {
        BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
        DecimalFormat df = new DecimalFormat ("#");
        BufferedReader reader = new BufferedReader (new FileReader ("unsorted.txt"));
        //BufferedWriter writer = new BufferedWriter (new FileWriter ("test.txt", true)); // text to write


        int[] numbers = new int [Max];  // if its int the 0's in the beginiing would be cut off
        String line = null;
        int[] count = {0};

        int low = 0;
        int high = count [0] - 1;


        while ((line = reader.readLine ()) != null)
        {
            numbers [count [0]] = Integer.parseInt (line);
            System.out.println (numbers [count [0]]);

            count [0]++;
        }
        reader.close ();
        System.out.println ();
        System.out.println ("There are " + count [0] + " numbers.");
        System.out.println ();


        ///////////////////////////////////////////////////////////////////////////////


        MergeSort (numbers, 0, count [0] - 1);

        for (int i = 0 ; i < count [0] ; i++)
        {
            System.out.println (numbers [i]);
        }




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

    Of course a method may invoke another method. The only confusing part here is that this method is static, which means it is invoked on a class instead of an object. Since it is called inside of the class it is defined in, you do not need to write MergeSortExample.MergeSort(). If you want to understand the differences between static and instance methods and fields, I suggest you look at the tutorials on the Java website.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here are the full codes that I am using to implement this program. Everything
Below is the program that I wrote. /******************************************************************************* * This program reads EOF from
I am writing a function that is supposed to sort an array using merge
So I have this program that fetches a page using a short link (I
So I have this program that fetches a page using a short link (I
I have a program that sorts big files by splitting them into chunks, sort
I have this program that should execute a piece of code base on the
I bought this program that created a pretty nice imageuploader flash script however I
I have this program that I am working on for class, I think the
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,

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.