Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do I do the selection sort in python and c?

+9 votes
asked Mar 2 by Jovia Dawkins (210 points)

2 Answers

0 votes
answered Mar 3 by Peter Minarik (101,340 points)

Here is the algorithm explained. You can do your own implementation in the desired language.

Share your work for review if help is needed.

Good luck!

+1 vote
answered Apr 19 by Vipul Kumar (280 points)
PYTHON

l=[42, 7, 19, 73, 5, 88, 12, 34, 67, 1, 25, 90, 16, 53, 29]
n=len(l)
for i in range(n-1):
    for j in range(i+1,n):
        if l[j]<l[i]:
            l[i],l[j]=l[j],l[i]
print(l)



C

#include <stdio.h>
void main(){
    int l[15]={42, 7, 19, 73, 5, 88, 12, 34, 67, 1, 25, 90, 16, 53, 29},i,j;
    for (i=0;i<14;i++){
        for (j=i+1;j<15;j++){
            if (l[j]<l[i]){
                l[i]=l[i]+l[j];
                l[j]=l[i]-l[j];
                l[i]=l[i]-l[j];
            }
        }
    }
    printf("{");
    for (i=0;i<15;i++){
        printf(" %d ,",l[i]);
    }
    printf("}");
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...