[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
I just spent two hours trying to implement Selection Sort in
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 17
Thread images: 6
File: maxresdefault.jpg (88 KB, 1440x1080) Image search: [Google]
maxresdefault.jpg
88 KB, 1440x1080
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
>>
File: photo.jpg (17 KB, 265x265) Image search: [Google]
photo.jpg
17 KB, 265x265
>>54407863
>/*
>single line comments
>>
I'n trying to implement a binary tree. Ill prob give up and look for the answer. FML
>>
File: IMG_1394.jpg (231 KB, 640x640) Image search: [Google]
IMG_1394.jpg
231 KB, 640x640
>>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.
>>
File: N1h.png (8 KB, 576x103) Image search: [Google]
N1h.png
8 KB, 576x103
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!
>>
File: 1NP9CUu.jpg (46 KB, 530x560) Image search: [Google]
1NP9CUu.jpg
46 KB, 530x560
>>54407711

It's ok, you have to start somewhere.
>>
Thread replies: 17
Thread images: 6

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.