java - Recursive Search Method that calls itself returns the wrong value -


I am writing a method that searches the network for a peer network in a simple peer. The method I have written, the Wolf's Residential client takes a point in this network and checks that if the client was calling, the SearchForResponsibleClient method is responsible for this point.

If it is responsible then it returns itself

If it is not responsible then it sees its client neighbors (which is saved in the object) and checks that Is anyone responsible for the neighbors and if such a neighbor falls ...

These two scenarios work fine.

If neighbors are not responsible, then how to take the first neighbor of the calling client Goes and explores distress Client method is called again repeated.

When I call it again, I get the correct output on the console but wrong return value.

Here is my code:

  Search the public client interfaceForrespicious client (status P) {System.out.println ("Forge Resolcable Client For This Search" + this.uniqueID ); Boolean contains = this.clientArea.contains (P); System.out.println ("Calling Client:" + this.uniqueID); System.out.println ("Contains elements in the current client:" + included); // If the existing client is included in the document {in} {System.out.println ("The current element is responsible" + this.uniqueID); This return; } // apparently the current customer is not responsible, customers can check the neighbors. Println ("++++++++++++++++++++++++++++++++++++"); System.out.println ("Calling element:" + this.uniqueID + "is in the neighbors:"); (Client Interface Neighbor: this.neighbs) {System.out.println (neighbour.getUniqueID ()); System.out.println ("Status is included:" + neighbour.getArea (.) Contains (P)); If (neighborhood.Getieria (.) In (P)) {System.out.println ("Found a Golden Neighbor;", + Neighborhood.GetuonicID); Returning neighbor; }} System.out.println ("++++++++++++++++++++++++++++++++++++++++++++ +++++++ "++"); // If the neighbors are not responsible, then get the first neighbor of the neighboring list and restart the search. Out.println ("The first neighboring element is responsible:" + temporary client Gatereia (.) Contains (P);; (! TemporalClient.getArea (.). (P)) {system.out.println ("A And this client who is searching is calling: "+ this.uniqueID +" with the client who found it but was not correct: "Temporary Client. Getenicic IDID ()); temporalClient.searchForResponsibleClient (P);} and {back Cordic Client;} System.out.println (" !!!!!! " Should return !!!!! "); returning tap;}  

And here's the output from my console:

Calling searchForResponsibleClient with the client < Client calling: client0
Current clients include elements: incorrect; +++++++++++++++++++++++++++++++++++++++++++ +++++++++ Calling element: Client0 has neighbors:
client3
s Status is included: False ++++++++++++++++++++++++++++++++++++++++ ++++++++++ The neighboring element is responsible first: false
is doing another search that this client is calling: The client with the client who found it but was not correct: Client3 < Br> Call calling Client 3: client3
Current client includes elements: false
+ +++++ ++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++ Client4
!!!!!! Reached the position that never reached me. !!!!!

In this case, there should be a situation in client 4 (which is actually the case) but the client4 is returned back instead of the tap, which causes a NullpointerException. I should have made a mistake with my return statement but in some way I do not know where the mistake can be.

You have to return the last value you got to see, like this modifying the line:

  temporalClient.searchForResponsibleClient (p);  

to

  return temporary client .searchForResponsibleClient (P);  

should move you to explain why you are reaching the code you do not think you should


Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -