Posts

Showing posts from 2022

AoA

 Selection Sort : Algorithm:  Step 1 − Set min to the first location Step 2 − Search the minimum element in the array  Step 3 – swap the first location with the minimum value in the array Step 4 – assign the second element as min.  Step 5 − Repeat the process until we get a sorted array. Program Code:   #include <stdio.h> int main() {  int arr[100], n, i, j, position, swap; printf("Enter number of elements\n"); scanf("%d", &n); printf("Enter %d Numbers\n", n);  for(i = 0; i < n; i++)     scanf("%d", &arr[i]); for (i = 0; i < (n - 1); i++) {       position = i;       for (j = i + 1; j < n; j++) {          if (arr[position] > arr[j])             position = j;       }       if (position != i) {          swap = arr[i];          arr[i] = arr[position];          arr[position] = swap;       }    }    for (i = 0; i < n; i++)       printf("%d\t", arr[i]);    return 0; } INSERTION SORT: Algorithm: Step 1 − If the elem