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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:14:36+00:00 2026-06-02T07:14:36+00:00

I have been trying to implement various types of sort in a program am

  • 0

I have been trying to implement various types of sort in a program am working on. So far i’ve managed to sort integers.What changes have to be made in order to make this (merge) code sort a String array instead of an int one?
Will the time complexity vary? if so, for better or for worse?

EDIT 1: tried to use the compareTo. something does not seem right. Errors are returned e.g
Cannot convert from string to int and vice versa. FIXED

EDIT 2: im getting NullPointerException at line if (array[low].compareTo(array[high]) >= 0) . Suggestions are always welcome.

This is the error:

null  null  null  null  null  
Exception in thread "main" java.lang.NullPointerException
    at Merge.mergeSort_srt(Merge.java:28)
    at Merge.Sort(Merge.java:15)
    at Sort.main(Sort.java:73)

import java.io.File;


public class Merge 
{
    public void Sort (LinkedList listIn, int size) throws Exception
    {
        String[] mergeArray = new String[size] ;
        String textContent = null ;
        File outputFile ;

         for(int i = 0; i < mergeArray.length; i++)
           System.out.print( mergeArray[i]+"  ");
           System.out.println();
           mergeSort_srt(mergeArray,0, mergeArray.length-1);
           System.out.print("Values after the sort:\n");
           for(int i = 0; i <mergeArray.length; i++)
           System.out.print(mergeArray[i]+"  ");
           System.out.println();
           System.out.println("PAUSE");
    }


     public static void mergeSort_srt(String array[],int lo, int n)
     {
           int low = lo;
           int high = n;
           if (array[low].compareToIgnoreCase(array[high]) >= 0)
           {
               return;
           }

           int middle = ((n+1)/ 2);
           mergeSort_srt(array, low, middle);
           mergeSort_srt(array, middle + 1, high);
           int end_low = middle;
           int start_high = middle + 1;
           while ((array[low].compareToIgnoreCase(array[end_low]) <= 0) && (array[start_high].compareToIgnoreCase(array[high]) <= 0))
           {
               if(array[low].compareToIgnoreCase(array[start_high]) < 0)
               {
                   low++;
               }
               else
               {
                   String Temp = array[start_high];
           for (int k = start_high- 1; k >= low; k--)
           {
               array[k+1] = array[k];
           }
           array[low] = Temp;
           low++;
           end_low++;
           start_high++;
           }
           }
     }

}
  • 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-02T07:14:41+00:00Added an answer on June 2, 2026 at 7:14 am

    It depends on the way you want to sort your Strings, but the method compareTo of String would help you achieve that kind of sorting:

    Returns:
    the value 0 if the argument string is equal to this string; a value less than 0 if this string is lexicographically less than the string argument; and a value greater than 0 if this string is lexicographically greater than the string argument.

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

Sidebar

Related Questions

I have been trying to implement counting sort. It requests the user for the
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
Hello guys, I have been trying to implement the DSUM function but failed to
I use Devise (1.4.8) for my User model and have been trying to implement
I've been trying to implement unit testing and currently have some code that does
Im trying to implement an Observer/Observable pattern on an EC2 instance. I have been
I have been trying this for the whole day and I managed to make
I have been trying to implement 2 Seperate Contact Modals based off an original
I have been trying to make a Pong clone as sort of a beginner's
I have been trying to implement a small SERVER - CLIENT app but ran

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.