How to write a C Program For Selection Sort Using C Programming Language ?
In computer science, selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. Selection sort is noted for its simplicity, and it has performance advantages over more complicated algorithms in certain situations, particularly where auxiliary memory is limited.
See More : Selection sort
Solution For C Program:
//C Program For SELECTION SORT
#include<stdio.h>
main()
{
int i,n,a[50];
clrscr();
printf("enter how many elements do u want to enter: ");
scanf("%d",&n);
printf("enter the array elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
sel_sort(a,n);
getch();
}
sel_sort(int a[],int n)
{
int i,j,temp,pass,min;
for(pass=0;pass<n-1;pass++)
{
min=pass; /*assume that pass is the minimum index*/
for(j=pass+1;j<n;j++)
{
if(a[min]>a[j]) /*update min*/
min=j;
}
if(min!=pass) /*swaping elements*/
{
temp=a[pass];
a[pass]=a[min];
a[min]=temp;
}
}
printf("final sorted array is: ");
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
Learn More :
Sort
- Sort Three Numbers - program reads in three Integers and displays them in ascending order.
- C Program Sort Example
- C Program Shell Sort Using C Programming Language
- C Program to Bubble Sort Using C Programming Language
- C Program Insertion Sort Using C Programming Language
- Heap Sort Using C Programming Language
- C Program To Sort An Array In Ascending And Descending Order
- C Program To Sort An Array Of Names In Alphabetical And Reverse Order
- C Program Sort Array By Segment
- C Program to sort an array using bubble sort
- C Program to merge and sort two arrays
- Un-sortiertes Array and Sortiertes Array
- matrix sort in C Program
- C program that receives 10 float numbers from the console and sort them in non-ascending order, and prints the result
- C Program to accept 5 names from user & store these names into an array. Sort these array elements in alphabetical order
- C Program to accept n numbers from user,store these numbers into an array & sort the number of an array
- C Program to Implement Quick Sort
- QuickVSInsertion Sorting C Program
Selection Sort