C Online Compiler
Example: Merge Sort Recursive Division in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Merge Sort Recursive Division #include <stdio.h> void mergeSort(int arr[], int left, int right) { // Base case: if the sub-array has one or zero elements, it's already sorted if (left < right) { // Find the middle point of the current sub-array int mid = left + (right - left) / 2; // Recursively sort the first half mergeSort(arr, left, mid); // Recursively sort the second half mergeSort(arr, mid + 1, right); // After the halves are sorted, merge them (merge function would be called here) // merge(arr, left, mid, right); } }
Output
Clear
ADVERTISEMENTS