
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program for Recursive Bubble Sort
Following is the Java Program for Recursice Bubble Sort −
Example
import java.util.Arrays; public class Demo{ static void bubble_sort(int my_arr[], int len_arr){ if (len_arr == 1) return; for (int i=0; i<len_arr-1; i++) if (my_arr[i] > my_arr[i+1]){ int temp = my_arr[i]; my_arr[i] = my_arr[i+1]; my_arr[i+1] = temp; } bubble_sort(my_arr, len_arr-1); } public static void main(String[] args){ int my_arr[] = {45, 67, 89, 31, 63, 0, 21, 12}; bubble_sort(my_arr, my_arr.length); System.out.println("The array after implementing bubble sort is "); System.out.println(Arrays.toString(my_arr)); } }
Output
The array after implementing bubble sort is [0, 12, 21, 31, 45, 63, 67, 89]
A function named 'Demo' contains the function to perform bubble sort. If the length of the array is 1, then the array is returned. Otherwise, the array is iterated over and if the element at the first place is greater than the element at the next position, the elements are swapped.
After the first pass, the largest element would have been fixed, and the bubble sort is called on all elements except the largest once. In the main function, the array is defined and it is passed as a parameter to the bubble sort function.
- Related Articles
- C++ Program for Recursive Bubble Sort?
- C Program for Recursive Bubble Sort
- C++ Program for the Recursive Bubble Sort?
- Java Program for Recursive Insertion Sort
- Python Program for Bubble Sort
- 8085 program for bubble sort
- Java program to implement bubble sort
- Python Program for Recursive Insertion Sort
- C Program for Recursive Insertion Sort
- Bubble sort in Java.
- Bubble Sort program in C#
- C++ Program to Implement Bubble Sort
- Bubble Sort
- C++ Program Recursive Insertion Sort
- Java Program for Binary Search (Recursive)

Advertisements