Selection Sort in C

[ad_1]

Selection Sort in C
#include "stdio.h"
void main(){
    int n,arr[100],i,j;
    printf("Enter the size of array");
    scanf(
    printf("Enter the elements of the array");
    for(int i=0;i
 
selection sort
def ssort(lst):
    for i in range(len(lst)):
        for j in range(i+1,len(lst)):
            if lst[i]>lst[j]:lst[j],lst[i]=lst[i],lst[j]
    return lst
if __name__=='__main__':
    lst=[int(i) for i in input('Enter the Numbers: ').split()]
    print(ssort(lst))
selection sort algorithm in c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include 
int main()
{
int a[100], n, i, j, position, swap;
printf("Enter number of elementsn");
scanf(
printf("Enter
for (i = 0; i < n; i++)
scanf(
for(i = 0; i < n - 1; i++)
{
position=i;
for(j = i + 1; j < n; j++)
{
if(a[position] > a[j])
position=j;
}
if(position != i)
{
swap=a[i];
a[i]=a[position];
a[position=swap;
}
}
printf("Sorted Array:n");
for(i = 0; i < n; i++)
printf(
return 0;
}

[ad_2]

Please follow and like us:
Content Protection by DMCA.com