
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ Program for the Recursive Bubble Sort?
In Bubble sort compares adjacent pairs and swaps them if they are in the wrong order. In this type of bubble sort we use the recursive function that calls itself.
Input:53421 Output:12345
Explanation
Use of recursive (self-calling) function compares adjacent pairs and swaps them if they are in the wrong order until the array is in order
Example
#include <iostream> using namespace std; void bubbleSort(int arr[], int n) { for (int i = 0; i < n - 1; i++) { if (arr[i] > arr[i + 1]) { int temp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = temp; } } if (n - 1 > 1) { bubbleSort(arr, n - 1); } } int main() { int arr[] = { 5,4,2,1,3 }; int n = 5; bubbleSort(arr, n); for (int i = 0; i < n; i++) { cout<< arr[i]<<"\t"; } return 0; }
- Related Articles
- C++ Program for Recursive Bubble Sort?
- Java Program for Recursive Bubble Sort
- C Program for Recursive Bubble Sort
- Python Program for Bubble Sort
- 8085 program for bubble sort
- Python Program for Recursive Insertion Sort
- C Program for Recursive Insertion Sort
- Java Program for Recursive Insertion Sort
- Bubble Sort program in C#
- Java program to implement bubble sort
- C++ Program to Implement Bubble Sort
- Bubble Sort
- C++ Program Recursive Insertion Sort
- JavaScript Bubble sort for objects in an array
- 8085 Program to perform sorting using bubble sort

Advertisements