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

simple sorting algorithm. only check two numbers at a time.

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 19
Thread images: 3

File: PicsArt_08-22-09.46.22.jpg (666KB, 1397x1675px) Image search: [Google]
PicsArt_08-22-09.46.22.jpg
666KB, 1397x1675px
simple sorting algorithm.

only check two numbers at a time.
if the number in the lower array index is higher than the number in the higher array index.
>switch numbers


>spot the mistake
>>
>>56214265
>Help me with minor assignment #1
>>
>spot the mistake

OP
>>
>>56214265
The mistake you are using bubble sorting that's the mistake
>>
File: tängker på matte.jpg (56KB, 418x720px) Image search: [Google]
tängker på matte.jpg
56KB, 418x720px
>>56214265
The mistake is trivial and is left as an exercise to the reader
>>
>niggersort
>that break; means you will swap only one element in the array.
>>
>C++
>>
>>56214265
At least have the decence of begging for someone to do your homework...
>>
>>56214347
>image
Fuck quantum physics
>>
>>56214265
The inner loop is initialized to 1. This is bad, because you basically end up not sorting the array at all, at best only rearranging them.

I'll leave it up to you to figure out what you want to initialize k as, however.

Oh btw, there's another mistake in the outer loops' declaration as well. Not a mistake per-se, but a pointless extra loop that doesn't need to be there.
>>
>>56214265

break
also if you are checking i = 0, k = 1, then you need also i < AMOUNT - 1, and k < AMOUNT
>>
use fucking gdb
>>
>>56214265
>using bubble sort

>not using superior sleep sort.

Why are you over-complicating things?
>>
>>56214265
why are u using C++, i see no OOP

use C
>>
bubble sort is very unintuitive to me
>>
>>56214539
>you basically end up not sorting the array at all, at best only rearranging them.
This is correct. I was thinking we were looking at a bubblesort with some mistakes like the break, but bubblesort swaps adjacent entries only. It's not insertion sort or selection sort either.
>>
>>56214265
>Not creating a min heap to sort
>>
I bet more than half of you wouldn't even be able to roll your own quicksort without consulting google
>>
File: fq0A8hx.gif (219KB, 899x455px) Image search: [Google]
fq0A8hx.gif
219KB, 899x455px
>>56214265
Okay.
Thread posts: 19
Thread images: 3


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.