program1

Ads
 

program1

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.

Ads









Related Tutorials/Questions & Answers:
ModuleNotFoundError: No module named 'program1'
ModuleNotFoundError: No module named 'program1'  Hi, My Python... 'program1' How to remove the ModuleNotFoundError: No module named 'program1... to install padas library. You can install program1 python with following
Java - Java Beginners
Friend, 1)Another way: class Program1{ public static void main(String
Advertisements

Ads