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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Aman
program1
1 Answer(s)      6 years and 2 months ago
Posted in : Java Beginners



Advertisement
View Answers

November 18, 2008 at 1:27 AM


Hi Aman,



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

----------------------------------

Visit for more information.

http://www.roseindia.net/java/beginners/arrayexamples/InsertionSort.shtml

Thanks.


Related Tutorials/Questions & Answers:
program1 - Java Beginners
program1  Sir, can u help to learn about bubble sorting and selection sorting.......including programs.....  Hi Aman, public class BubbleSortDemo{ public static void main(String a[]){ int i; int
java beginners - Java Beginners
Friend, Try the following code: 1)Program1.java class Program1{ public...(); } System.out.println("a"); } } 2)Program2.java class Program1{ public static
Advertisements
java code and logic - Java Beginners
) class Program1{ public static void main(String args[]){ for(int i=1;i<=5;i+=2
java code and logic - Java Beginners
Program1{ public static void main(String[] args) { String st="STRING
Java Reverse String Pattern
; class Program1{ public static void main(String[] args
Java - Java Beginners
Friend, 1)Another way: class Program1{ public static void main(String
Advertisements
 

 

 

DMCA.com