I just spent two hours trying to implement Selection Sort in Python. Damn, I'm a shitty programmer.
>caring how long it took to implement something
What is selection sort? Share with us what you learned!
>>54407788/* a[0] to a[n-1] is the array to sort */
int i,j;
/* advance the position through the entire array */
/* (could do j < n-1 because single element is also min element) */
for (j = 0; j < n-1; j++) {
/* find the min element in the unsorted a[j .. n-1] */
/* assume the min is the first element */
int iMin = j;
/* test against elements after j to find the smallest */
for ( i = j+1; i < n; i++) {
/* if this element is less, then it is the new minimum */
if (a[i] < a[iMin]) {
/* found new minimum; remember its index */
iMin = i;
}
}
if(iMin != j) {
swap(a[j], a[iMin]);
}
}
https://en.wikipedia.org/wiki/Selection_sort
>>54407863
>/*
>single line comments
I'n trying to implement a binary tree. Ill prob give up and look for the answer. FML
>>54407711
its fucking up like this, and not giving up, that's turns shit coders into good coders. this is where learning comes from.
>>54407939
This.
Every one of us sucked when we started.
You eventually got it to work, right? So what exactly about this is a fail? You stuck with it and succeeded.
u must be pretty shit OP
Read some code m8, helps tremendously
>>54407895
b8?
>>54407863
that is not python
>>54408628#!/usr/bin/python
/* a[0] to a[n-1] is the array to sort */
int i,j;
/* advance the position through the entire array */
/* (could do j < n-1 because single element is also min element) */
for (j = 0; j < n-1; j++) {
/* find the min element in the unsorted a[j .. n-1] */
/* assume the min is the first element */
int iMin = j;
/* test against elements after j to find the smallest */
for ( i = j+1; i < n; i++) {
/* if this element is less, then it is the new minimum */
if (a[i] < a[iMin]) {
/* found new minimum; remember its index */
iMin = i;
}
}
if(iMin != j) {
swap(a[j], a[iMin]);
}
}
better nub?
>>54408682
kek
>>54407711
post code!
>>54407711
It's ok, you have to start somewhere.