Sorting in C: Bubble Sort, Selection Sort, and Insertion Sort

Sorting arranges data into a defined order (usually ascending or descending) — and as we saw in the previous post, a sorted array unlocks fast binary search. This post covers three classic, beginner-friendly sorting algorithms: bubble sort, selection sort, and insertion sort. This is Post 2 of the Unit III series — Post 1 covered … Read more

Sort an Array in Ascending Order Using Bubble Sort in C

This program sorts the elements of a 1-D array in ascending order using the bubble sort technique. C Program #include <stdio.h> int main() { int arr[100], n, i, j, temp; printf(“Enter number of elements: “); scanf(“%d”, &n); printf(“Enter %d elements:\n”, n); for (i = 0; i < n; i++) { scanf("%d", &arr[i]); } for (i ... Read more