#BubbleSort #SortingAlgorithm #AdjacentElements #SwappingElements #WrongOrder #SortingList #Programming #Algorithm #ComputerScience
#selectionsort #SortingAlgorithm #SimpleAlgorithm #UnsortedList #SortedPortion #UnsortedPortion #SmallestElement #MovingElement #BeginningOfList #DividingList #Algorithm #Programming #ComputerScience
Sorting is the process of arranging a collection of elements in a particular order. The elements could be numbers, strings, or any other data types. Sorting is an important operation in computer science and is used in a wide range of applications, including data analysis, database management, and algorithm design.
There are many different algorithms for sorting, each with their own advantages and disadvantages. Some of the most commonly used sorting algorithms include:
Bubble sort - In this algorithm, adjacent elements are compared and swapped if they are in the wrong order. This process is repeated until the entire list is sorted.
// use sign in place of lessthansign YouTube not supporting Sign
// so we are not using sign
#include lessthansign stdio.h graterthansign
void main() {
int i, j, temp;
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n = 7;
for (i = 0; i lessthansign n; i++) {
for (j = 0; j lessthansign n-i-1; j++) {
if (arr[j] lessthansign arr[j+1]) {
// swap arr[j] and arr[j+1]
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
} // use sign in place of lessthansign YouTube not supporting Sign
// so we are not using sign
printf("Sorted array: \n");
for (int i = 0; i lessthansign n; i++) {
printf("%d ", arr[i]);
}
}
Selection Sort- Selection sort is a simple sorting algorithm that works by repeatedly finding the smallest element in an unsorted portion of a list and moving it to the beginning of the list.
#include lessthansign stdio.h graterthansign
void main() {
int i, j, idx, temp;
int arr[] = {64, 34, 25, 12, 22, 11, 90};
int n =7;
for (i = 0; i lessthansign n; i++) {
idx= i;
for (j = i+1; j lessthansign n; j++) {
if (arr[j] lessthansign arr[ idx]) {
idx = j;
}
}
temp = arr[i];
arr[i] = arr[ idx];
arr[ idx] = temp;
}
printf("Sorted array: \n");
for (int i = 0; i lessthansign n; i++) {
printf("%d ", arr[i]);
}
}
On this page of the site you can watch the video online Sorting in C | Bubble Sort & Selection Sort | Sorting Algorithm step by step | Mastering C Language with a duration of hours minute second in good quality, which was uploaded by the user The Global Computer Society Nainital 02 April 2023, share the link with friends and acquaintances, this video has already been watched 22 times on youtube and it was liked by 3 viewers. Enjoy your viewing!