Wednesday, December 19
BubbleSort program in Java
Hi All,
package Sorting;
/**
*
* @author SKiTECH
*/
public class bubbleSort {
public static void main(String arg[]) {
int a[] = {100, 30, 80, 20, 2, 90, 50, 11, 99, 99};
int temp = 0;
System.out.println("Ascending sort program");
for (int i = a.length - 1; i >= 0; i--) {
for (int j = 0; j < i; j++) {
if (a[j] < a[j + 1])
{ // if you want descending order change ">" symbol instead of "<" (a[j] > a[j + 1])
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
System.out.println(a[i]);
}
}
}
OUTPUT:
~~~~~~~~
Ascending sort program
2
11
20
30
50
80
90
99
99
100
Descending sort program
100
99
99
90
80
50
30
20
11
2
Subscribe to:
Post Comments (Atom)
Backup files to google drive using PHP coding
Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...
-
Hi All, "No bootable device – insert boot disk and press any key" Solution ...
-
Hi All, Here I write a program for Email with an attached excel document using PHP. Also I design dynamic table for maintaining c...
-
Hi All, Welcome to the TECHIE SNACKS world. The main theme of this blog is sharing the Knowledge in various domains and platforms o...
No comments:
Post a Comment