I'm a Senior Software Engineer and it took me 12 hours to implement an O(n) sorting algorithm using a linked list in C, a programming language I have been using for a decade now.
I kept on forgetting to reassign the contents of the head address when an item was being added to the head of the list.
If it makes you feel any better, I feel like much less of a retard now.
Carter Roberts
Tell us more, user. Do you have some early buggy code and the final result? Why'd you sort the linked list directly instead of mapping it an array, sorting the array, and then mutating the original list according to the sorted array? How long did it take you notice that you were forgetting stuff and what did you do about that? Nothing and keep forgetting? Use a macro that would remember the task for you? How were you testing to see that your sort worked? Just call it from an existing application? Call it from a test suite?
Colton James
I first wrote it into the existing software, and realized I fucked up. I then created a small test application that did what I wanted and It worked just fine for the inputs I gave it. I then went back and implemented the damn thing and it still didn't work.
Dylan Hall
so your tests were incomplete? or you broke it while moving it from the test code back into your application?
Joseph Ortiz
Yes I didn't consider one of the cases. Simply going back to my test code and using a different case would have solved my problem.
Lucas Reyes
Here's my little shitty piece of code. Ignore the stuff that's not the actual sorting algorithm.
please put this god-tier cringe in its own thread. why give the reader whiplash? use commas to assign node and i at the same time, and then to update i and node at the same time. actually I'd prefer int i = 0; for(node = head; node != NULL; node = node->next) { printf("%d ", node->pri); list_sorted[node->idx] = i++;the mixed variables just looks too much like an error to leave. does your real code also know the length of the list in advance, or is that part of the arrays that you have for test purposes? if you wrote a cons() and didn't care about garbage collection it'd be just as easy to construct a test list as to use an array like this. is this sort really O(N)?
Joshua Rivera
The static array was only for testing purposes. I was iterating over a function call to get the contents to be sorted.
Try coding in an environment where an error is thrown if you don't cast the return from malloc.
I was being lazy, the final implementation is just a while(node) with the index being incremented separately.
>It's easier to think you know C++, but you're going to be wrong: youtube.com/watch?v=PNRju6_yn3o Is there a dress code for these events that requires speakers to dress as faggily as possible? He looks decent in the photo when he's wearing a suit, but he looks just awful on stage. No wonder the field or programming gets no respect when its members act like overgrown toddlers. Sage for OT
12 hours to overturn a fundamental rule of computer science is nothing. Be proud of yourself, OP, and remember us when you collect your ACM award.
Daniel Nguyen
This. You seem to have a version of insertion sort, which is O(n^2). You have a while loop inside a for loop. I'm not sure it's even possible to sort in O(n) time with a linked list, unless you do counting sort with an array and then convert it to a linked list.
Why are you using a linked list in the first place? Also if you do know the length of the list, couldn't you allocate shit at once outside the for loop? I'm thinking it'd be faster since your memory is in one place and you'd avoid some caching bullshit, but if it's a linked list it might not matter anyways.
Zachary Ramirez
It's because he's fat. The only way fat people can look okay is wearing a well tailored suit. Donald Trump is a good example of this. In his suits he looks like an absolute boss, but if you see him golf attire, you notice he's quite obese.
Lincoln Jackson
It is a convention about C++. Who do you think is the audience? Faggots that care about how other faggots dress or men who care about C++? spotted the LARPer
Austin Wilson
___ eye for the C++ guy. what language is it?
Joseph Young
Imagine a Rustcon. Nothing but neckbeard dudes in female cosplay outfits blowing each other.