Need help with Java - recursion

Talk about things which are not related to RoR or War.

Moderators: Developer, Management, Web Developer

Forum rules
Before posting on this forum, be sure to read the Terms of Use
User avatar
Posts: 68

Need help with Java - recursion

Post#1 » Wed Sep 26, 2018 10:00 am

Decided I'd post this here for fun (and perhaps even a helpful answer), as I know obviously that the devs are experienced in programming, and perhaps others here are too. If you are bored and/or have some free time, feel free to contribute and help me out! :D I'm a first year computer engineering student and having trouble with a Java method to do with recursion in one of my assignments, here is the problem:

So I have a tree structure here of an organization hierarchy - each node/employee object contains a field with the Set of the nodes/employees under him. So for example, AA has a set which in it has AS, BV, CW and DM. And BV has a set which contains BK and BL. Also, each employee has a field with their x, y coordinates.


The program has a recursive method which, when the user releases the mouse on one of the employees, it traverses the tree (starting from AA the CEO), until it find the employee with the x, y coordinates of where the mouse was released.

Here is the method: the parameters x, y are where the mouse has been released, and empl is the CEO (the root of the tree).


The problem is that the method doesn't return an employee (it returns 'null'), the only time it returns an employee is if the mouse has been released on the CEO/root of the tree. But if I release the mouse on any other employee, it returns 'null'.

I've tried to find the problem for about an hour to no avail. I think it might be something small, but so far it has eluded me.

So feel free to help me, if you have the inclination. If you solve my problem and you're on destro, I will give you a free +23 strength/WS/toughness or initiative tally of your choice. If you're on order, your reward will be for me not to kill you if I see you in-game. :D

*reward limited to the first person who solves it

User avatar
Posts: 514

Re: Need help with Java - recursion

Post#2 » Wed Sep 26, 2018 10:33 am

Alandrian wrote:
Wed Sep 26, 2018 10:00 am
dev sttuff
I'm not i dev but wanna try to guess.

If it's tree structure - then i suppouse that in cycle you just go for one branch till the end of it and then your cycle stops and return "null".

My propolsal is to dump every step of cycle and look what it returns.("Print" or something) ;)

And remember No FUN allowed in ROR.

Save the DDZEALOTs proposal viewtopic.php?f=95&t=28103&p=318980#p318980 8-)

User avatar
Posts: 346

Re: Need help with Java - recursion

Post#3 » Wed Sep 26, 2018 12:16 pm

Does it have to be recursive?
That logic looks flawed.
Instead of checking the whole subset in the field, you just check one and call the method again. You never check the whole tree.

If you have a graphical representation, that must have loaded from somewhere. You can get trace back of the click event and therefore don't have to browse the data structure.
Noiree - Archmage
Annnoying - Disciple of Wayne

gone with the wipe - RIP:
Annoying Lilpieceofsh - Disciple of Khaine, Bikinibabe Withoutbeach - Sorceress, Kekshirn Derkruemlige - Shaman

Posts: 1

Re: Need help with Java - recursion

Post#4 » Mon Mar 25, 2019 9:41 am

Excellent topic. I got useful information here. Thanks for such an excellent thread! I got solution.

Who is online

Users browsing this forum: No registered users and 4 guests