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! 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.
*reward limited to the first person who solves it
Need help with Java - recursion
Forum rules
Before posting on this forum, be sure to read the Terms of Use
Before posting on this forum, be sure to read the Terms of Use
Ads
Re: Need help with Java - recursion
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)
Re: Need help with Java - recursion
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.
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
Annnoying - Disciple of Wayne
gone with the wipe - RIP:
Annoying Lilpieceofsh - Disciple of Khaine, Bikinibabe Withoutbeach - Sorceress, Kekshirn Derkruemlige - Shaman
Re: Need help with Java - recursion
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 17 guests