A program to demonstrate how to declare and use bubble sort algorithm using Java programming language.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Please subscribe to my channel https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg
=================================================
Want to support my channel?
GCash Account
Jake Pomperada
09173084360
Paypal
https://paypal.me/jakerpomperada
Patreon
https://www.patreon.com/jakerpomperada
Thank you very much for your support.
Program Listing
public class Main {
public static void bubble_sort(int[] arr) {
int n = arr.length;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
public static void main(String[] args) {
int[] arr = {-5, 134, 6, 450, 235, 15,51};
System.out.println();
System.out.println("\tBubble Sort in Java\n");
System.out.println("UnSorted Values");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
bubble_sort(arr);
System.out.println("Sorted Values");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}
No comments:
Post a Comment