[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
Nobody really understands how this code works, right?
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: 53
Thread images: 3
File: Capture.png (12 KB, 472x326) Image search: [Google]
Capture.png
12 KB, 472x326
Nobody really understands how this code works, right?
>>
It details which node to delete.
I seriously hope this was a facetious question.
>>
>>53391370
Great non-explanation. Everybody gets that it deletes a node, the real question is in which order the individual statements are executed
>>
>>53391378
from top to bottom?
Are you being serious right now?
>>
>>53391378
>the real question is in which order the individual statements are executed
are you FUCKING kidding me
>>
>>53391406
>top to bottom
How new are you?
>>
please be bait
>>
File: apB6nyB_460s_v1.jpg (28 KB, 460x471) Image search: [Google]
apB6nyB_460s_v1.jpg
28 KB, 460x471
>>53391453
This indeed, hope its bait.

Stupid fuck OP
>>
>>53391347
It's just a normal binary search tree.
>>
>>53391406
Don't CPUs schedule instructions differently from how they appear in the source?

Doesn't look like the OP code is using any synchronization mechanisms
>>
it installs gentoo and then fucks your waifu
>>
>>53391522
I have a real gf so i dont need your imaginary drawings
>>
>>53391527
Fag.
>>
>>53391347
>winbabby

This is NOT a bait, guys
>>
File: vomit.jpg (25 KB, 395x405) Image search: [Google]
vomit.jpg
25 KB, 395x405
>>53391527
>real gf
>>
>>53391519
Ok this is definitely bait
>>
>>53391537
It's true though

The order that you call instructions in a program isn't mirrored on the CPU
>>
>>53391563
Prove it.
>>
>>53391578
https://en.wikipedia.org/wiki/Out-of-order_execution
>>
>>53391347
I do, but I won't tell you :^)
>>
>>53391347
Are you serious?

That is tree algorithms 101.
>>
>>53391659
I learned useful information such as how to write clean code, comment well, design patterns etc

Not this fucking useless nonsense that's going to be done for me already in a class anyway
>>
It traverses a binary tree until it throws a null pointer exception when it hits a leaf node.
>>
>>53391745
That doesn't explain anything about how the code works.
>>
>>53391760
What kind of detail are you looking for?
>>
>>53391782
Where and why the code continues after some specific return statements e.g. after return node.leftNode the program jumps to node.leftNode = delete(node.leftNode,..... hence calling the function all again
>>
>>53391347
I'm telling Jonas.
>>
You seem to be confused about how method invocation works.

The return is returning to the stack that called it.

Are you tracing the code and seeing "jump"?
>>
>>53391691
Prime example of those who rip on CS degrees saying they learnt "pretty much the same" self taught.
This is baby tree deletion using recursion. Taught in 99% of algorithms/data structures classes.
>>
>>53391831
You got this far in your course without ever understand recursion?
>>
>>53391933
>far
Been studying CS for a couple of months
>>
>>53391691
Self taught """"""programmers"""""" everyone.
>>
Not OP, but want to be sure I don't have this fucked up:
You can set "node" to the maximum of the left subtree (deleting the maximum accordingly) instead of the minimum of the right subtree, right?

Polite sage
>>
Didn't know we had cringe threads here on /g/
>>
A binary search tree, in REVERSE? wow, that's fucking amazing

sage
>>
>>53391519
>synchronization mechanisms
Like not being multi threaded?
>>
>>53391995
>>53391884
Don't bash self-taught programmers, I'm one of them.If this guy can't understand binary trees he isn't an autodidact, he is simply retarded, who thinks in terms of enterprise management bullshit. People who think only in design patterns and clean code are generally qualify as retards in most cases.
Started out with C64 BASIC which has control structures almost like Assembly (thankfully; GOTO/GOSUB - JMP/CALL). After that I learned C, Assembly and how to build a computer with a Z80 cpu by myself though, not design patterns. They're a lot more interesting. I learned about DPs later. I always liked low-level stuff/electronics though, instead of "apps". I entered university later though.
>>53391691
One of the first things I intuitively realized about full binary trees is how to pack them into an array. A lot of shit about them is intuitive, like breadth-first or depth-first search/walking.
Recursion is almost always natural to use for walking a tree. Binary trees aren't hard especially if you got a book and you can read and understand written words.
>Not this fucking useless nonsense that's going to be done for me...
Yeah, sure. Do that on a microcontroller.
>>
How come that temporary node isn't malloc'd?
I thought that all complex data structures have to be malloc'd so as to not upset the C Gods, Thompson, Ritchie, and Kernighan.
>>
>>53392931
It's Java. So all that shit you see there are references (pointers). They simply set the temp reference to point to wherever they want it to point.
Why would you want to malloc it? It's probably used by a single thread and blocks.
>>
>>53391347
It's an incorrect code that will produce stack overflow.
>>
>>53392903
Not bashing on self programmers. Bashing on elitist idiots not seeing the worth in a degree when they hardly know how to program past hello world and bloody fizzbuzz
>>
>>53391347
>java

noped
>>
>>53392903
This guy knows what's up. I too am a self taught programmer and I'm sick to death of plebs with degrees acting like they're superior just because they bullshitted their way through uni to get an overpriced piece of paper that says they're knowledgeable when in reality they know nothing but code monkey tier bullshit at best.
>>
>>53392970
Okay, thanks. It came out a bit like that in text. Although to tell you the truth, I don't always defend self-taught programmers though, because the majority are unfortunately bad and all they do is copy-paste badly. So having a bad opinion about them proves correct in most cases, it's the rest who suffer, if they drop their CV because they take that as a hard rule.
Plus as I said I entered university later so technically most people don't know I'm self-taught. Except probably that at my internship they saw I knew more than the average guy.
>>53392987
This can be seen every day at universities.
Most of these guys get into some very enterprise software development methodologies and they do some kind of app or web dev in Java or C#. I'm not saying that jobs like that never require a good mastery of programming, but those are exactly the kind of jobs where you can in the majority of the cases do without it.
A close friend of mine worked in a C# dev. group and when the other devs didn't have access to a sort method on an array they couldn't sort it themselves, he had to implement it for them.
>>
>>53392903
>microcontroller

Like I said, I work on real stuff and not this grunt work nonsense
>>
>>53393129
Okay, you must be baiting. This is it. Now, I know.
>>
>>53392903
You can't compare low level programming to high level. Low level is way easier and any retard can understand that.
>>
>>53392591
Kek!
>>
>>53391347
I understand how it works but it's written like shit. (Of course, it's Java so what do you expect?)

Here, have this:

delete :: Ord a => a -> BST a -> BST a
delete x (Node v l r) = case compare x v of
LT -> Node v (delete x l) r
GT -> Node v l (delete x r)
EQ -> merge l r

merge :: Ord a => BST a -> BST a -> BST a
merge x Nil = x
merge Nil y = y
merge x y
| size y > size x = Node vy x y'
| otherwise = Node vx x' y
where Just (vy,y') = extractMin y
Just (vx,x') = extractMax x

extractMax :: Ord a => BST a -> Maybe (a, BST a)
extractMax Nil = Nothing
extractMax (Node v l r) = case extractMax r of
Nothing -> Just (v, l)
Just (v',r') -> Just (v', Node v l r')

-- analog for extractMin
>>
>>53394760
Also feel free to assume size is O(1) and that `Node` is just a magic wrapper around an optimize tree that includes cached size etc.
>>
>>53391519
Sup OP
>>
>>53394248
>Low level is way easier and any retard can understand that.
lol. this must be bait.
>>
>>53392987
wow it's almost like there are retards without degrees and retards with degrees

you should publish your findings
Thread replies: 53
Thread images: 3

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.