SORTING
1
INTRODUCTION
Sorting is a technique used to arrange
elements of an array/list in a specific order
There are various sorting algorithms that
can be used to complete this operation.
Bubble sort is one of the sorting
technique that compares two adjacent
elements and swaps them until they are in
the intended order.
2
3
#include <stdio.h>
int main() {
int arr[] = {29, 10, 14, 37, 13};
int n, i, j, temp;
printf(“Enter the number of elements”);
scanf(“%d”,&n);
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
printf("Sorted array: ");
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
return 0;
}