Sorting in C | Bubble Sort & Selection Sort | Sorting Algorithm step by step | Mastering C Language

Publié le: 02 avril 2023
sur la chaîne: The Global Computer Society Nainital
22
3

#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]);
}

}


Sur cette page du site, vous pouvez voir la vidéo en ligne Sorting in C | Bubble Sort & Selection Sort | Sorting Algorithm step by step | Mastering C Language durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur The Global Computer Society Nainital 02 avril 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 22 fois et il a aimé 3 téléspectateurs. Bon visionnage!