problem related to array ..........
hello every one...
i need a little help regarding my homework in java,
its a merge sort program.i want to modify it so that it can sort both the integers and strings both .but string array is not working for integers as its considering integer as string so its sorting like:
21 12 23 3
sorted values:12 ,21,23,3
i think now u got my point what i want to say.
put do some thing with this code so that it can take input as integer and string both and sort them properly.
plz help me i have just 2 dayz for submission of this work.....
import java.util.*;
public class MergeSort{
public static void main(String a[]){
int i;
int array[] =new int[5];
Scanner input=new Scanner(System.in);
System.out.println(" MergeSort\n\n");
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
{
array[i]=input.nextInt();
}
System.out.println();
mergeSort_srt(array,0, array.length-1);
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ");
System.out.println();
System.out.println("PAUSE");
}
public static void mergeSort_srt(int array[],int lo, int n){
int low = lo;
int high = n;
if (low >= high) {
return;
}
int middle = (low + high) / 2;
mergeSort_srt(array, low, middle);
mergeSort_srt(array, middle + 1, high);
int end_low = middle;
int start_high = middle + 1;
while ((lo <= end_low) && (start_high <= high)) {
if (array[low] < array[start_high]) {
low++;
} else {
int 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++;
}
}
}
}