Algorithms_in_C  1.0.0
Set of algorithms implemented in C.
bubble_sort_recursion.c File Reference

Bubble sort algorithm implementation using recursion. More...

#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
Include dependency graph for bubble_sort_recursion.c:

Functions

void swap (int *first, int *second)
 Swapped two numbers using pointer. More...
 
void bubbleSort (int *arr, int size)
 Bubble sort algorithm implements using recursion. More...
 
void test ()
 Test function.
 
int main ()
 Driver Code.
 

Detailed Description

Bubble sort algorithm implementation using recursion.

Function Documentation

◆ bubbleSort()

void bubbleSort ( int *  arr,
int  size 
)

Bubble sort algorithm implements using recursion.

Parameters
arrarray to be sorted
sizesize of array
30 {
31  if (size == 1)
32  {
33  return;
34  }
35  bool swapped = false;
36  for (int i = 0; i < size - 1; ++i)
37  {
38  if (arr[i] > arr[i + 1])
39  {
40  swap(arr + i, arr + i + 1);
41  swapped = true;
42  }
43  }
44  if (swapped)
45  {
46  bubbleSort(arr, size - 1);
47  }
48 }
Here is the call graph for this function:

◆ swap()

void swap ( int *  first,
int *  second 
)

Swapped two numbers using pointer.

Parameters
firstfirst pointer of first number
secondsecond pointer of second number
18 {
19  int temp = *first;
20  *first = *second;
21  *second = temp;
22 }
bubbleSort
void bubbleSort(int *arr, int size)
Bubble sort algorithm implements using recursion.
Definition: bubble_sort_recursion.c:29
swap
void swap(int *first, int *second)
Swapped two numbers using pointer.
Definition: bubble_sort_recursion.c:17