Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


bhaskarreddy
corejava
1 Answer(s)      5 years and 4 months ago
Posted in : Java Interview Questions



Advertisement
View Answers

July 18, 2009 at 5:01 PM


Hi Friend,

Try the following code:

public class MergeSort{
public static void main(String a[]){
int i;
int array[] = {12,9,4,99,120,1,3,10};
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array[i]+" ");
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();
}

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++;
}
}
}
}

Thanks


Related Tutorials/Questions & Answers:
CoreJava Project
CoreJava Project  Hi Sir, I need a simple project(using core Java, Swings, JDBC) on core Java... If you have please send to my account
Advertisements
corejava - Java Beginners
corejava pass by value semantics  Example of pass by value semantics in Core Java.  Hi friend,Java passes parameters to methods using pass by value semantics. That is, a copy of the value of each of the specified
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
;    Q 1. When should I use the abstract class rather...;   Q 2. What is hashcode? When is hashCode() used ? Ans : ... use the equals method to make an exact match.    Q 3. How can I get
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
;    Q 1. How can I get the full path of Explorer.exe... that system can be access from an applet loaded via the Internet.     Q 2....   Q 3. Is it possible to convert a string to an abstract path ? Ans
Corejava Interview,Corejava questions,Corejava Interview Questions,Corejava
;    Q 1 : How should I create an immutable class ? Ans...; Q 2 : Is println overloading or overriding ?  Ans : The println() method...;     Q 3 : What is dynamic method dispatch ?  Ans
JList
JList  pls tell me about the concept the JList in corejava? and tell me a suitable example
core java - Java Beginners
core java  how to create a login page using only corejava(not servlets,jsp,hibernate,springs,structs)and that created loginpage contains database(ms-access) the database contains data what ever u r enter and automatically date
HOW TO BECOME A GOOD PROGRAMMER
HOW TO BECOME A GOOD PROGRAMMER  I want to know how to become good programmer   Hi Friend, Please go through the following link: CoreJava Tutorials Here you will get lot of examples with illustration where you can
What is Locale - Java Beginners
://www.roseindia.net/tutorial/java/corejava/javatext
Eclipse - IDE Questions
Eclipse  Hi To All.. I am new to ECLIPSE IDE. Please suggest me any book which can give me complete idea of setting environment and development with basic to advance development of java like(corejava,servlet,jsp,struts,ejb
Java Locale
/corejava/javatext/parseAndFormatDateUsingLocale.html Thanks
autentication & authorisation - JSP-Servlet
/interviewquestions/corejava/null-marker-interfaces-in-java.shtml Thanks
 

 

 

DMCA.com