This is a Java program that implements the Bubble Sort algorithm to sort an array of integers in descending order. Here's a step-by-step breakdown of how the program works:
public class Bubble_Sort { public static void main(String[] args) { int i = 0; int j = 0; int t = 0; int a[] = {2, 65, 23, 13, 18, 30, 46, 17, 52, 78}; while(i < 10) { j = 9; while(j > i) { if(a[j] > a[j - 1]) { t = a[j]; a[j] = a[j - 1]; a[j - 1] = t; } j = j - 1; } i = i + 1; } System.out.println("Sorted Array in Descending Order .. "); i = 0; while(i < 10) { System.out.print(a[i] + " "); i = i + 1; } } }
Sorted Array in Descending Order .. 78 65 52 46 30 23 18 17 13 2
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions