Bubble Sort In C Using Recursion – If you are looking for a bubble sort program in C with recursion example, this C programming tutorial will help you to learn how to write a program for bubble sort in C. Just go through this C programming example to learn about bubble sort, we are sure that you will be able to write a C program for bubble sort using recursion.
Bubble Sort in C
Table of Contents
- What is Bubble Sort?
- Bubble Sort Example With Image
- Bubble Sort in C Program Using Recursion
- Bubble Sort Program in C Using Recursion – Source Code
- C Program for Bubble Sort Using Recursion – Output
- C Programming Tutorials
- C Programming Examples
What is Bubble Sort?
Bubble Sort is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.
Bubble Sort Example
This below image illustrates what is Bubble Sort in C.
C Programming Tutorials
- Bubble Sort Program in C Using Array
- Bubble Sort Program in C Using Function
- Stack Push Pop Program in C Using Arrays
- Factorial Program in C Using Pointers
- Factorial Program in C Using While Loop
- C Program For Factorial Using For Loop
- Factorial Program in C Using Recursion Function
Bubble Sort in C Using Recursion
Learn how to write a bubble sort in c using recursion. Writing a Bubble Sort C Program can be done using various techniques like an array, pointers, recursion, function but here in this program, we show how to write a bubble sort program in c using recursion in a proper way.
Bubble Sort Program in C Using Recursion – Source Code
You can copy paste the below bubble sort program in c compiler to check how the source code work. Or write your own Bubble Sort in C Using Function with the help of this below c program for bubble sort.
/* BUBBLE SORT PROGRAM IN C USING RECURSION - BUBBLESORT.C */
#include <stdio.h>
#include <stdlib.h>
/* sorts the given numbers in ascending order */
void bubbleSort(int *data, int n) {
int i, temp;
if (n > 0) {
for (i = 1; i < n; i++) {
if (data[i - 1] > data[i]) {
temp = data[i];
data[i] = data[i - 1];
data[i - 1] = temp;
}
}
bubbleSort(data, n - 1);
}
return;
}
int main() {
int i, n, *data;
/* get the number of inputs from the user */
printf("Enter the number of inputs:");
scanf("%d", &n);
/* dynamically allocate memory to store i/p values */
data = (int *) malloc(sizeof(int) * n);
/* get the input data from the user */
for (i = 0; i < n; i++) {
printf("data[%d]: ", i);
scanf("%d", &data[i]);
}
/* sorts the given numbers */ bubbleSort(data, n); /* print the sorted numbers */ printf("Data After Bubble Sort:\n"); for (i = 0; i < n; i++) { printf("%d ", data[i]); } printf("\n"); return 0; }
C PROGRAM FOR BUBBLE SORT – OUTPUT
After you compile and run the above bubble sort program in c using recursion, your C compiler asks you to enter elements for bubble sort. After you enter elements, the program will be executed and give output like below expected output using bubble sort functionality.
C PROGRAMMING EXAMPLES
- C Program To Reverse a String Using Pointers
- C Program To Swap Two Numbers Using Two Variables
- C Program To Swap Two Numbers Using Three Variables
- C Program For Prime Numbers – Check a Number is Prime or Not
- C Program To Reverse a String with Using Function
- C Program to Reverse a String without Using Function
- C Program to Reverse a Sting Using Recursion
- C Program For Palindrome String
- C Program For Palindrome Numbers
- C Program To Reverse a String with Using Function
- C Program To Reverse a String without Using Function
- C Program To Reverse a String Using Recursion