Equivalent of C's pointer to pointer in Java -


this question has answer here:

i unable pass pointer pointer argument function in java.i know java don't have pointers instead pass reference objects. want know how done. clear doubt pasting code snippet of program implementing.

in following program calling method "partition" method "quicksortrecur". work on c of time don't know how send parameters newhead , newend pointer pointer.

i have mentioned c equivalent of below lines , want know how can implement same in java?

java :

public listnode partition(listnode lhead,listnode lend,listnode newhead,listnode newend){          ---------          ---------          ---------      } public listnode quicksortrecur(listnode lhead,listnode lend){     listnode newhead=null;     listnode newend=null;     listnode pivot;           pivot=partition(lhead,lend,newhead,newend);     if(newhead==null)             {             system.out.println("this not updated ");             }        } 

c equivalent of above signature:

struct node *partition(struct node *head, struct node *end,                        struct node **newhead, struct node **newend){ }  struct node *quicksortrecur(struct node *head, struct node *end) { struct node *pivot = partition(head, end, &newhead, &newend); } 

considering c's pointer rough equivalent java's reference, rough equivalent pointer pointer mutable class encapsulating reference.

for example, can build this:

class listnodereference {     private listnode node;     public listnode getnode() {         return node;     }     public void setnode(listnode thenode) {         node = thenode;     } } 

you can pass listnodereference function can or set using , set methods, in same way c program uses single dereference actual pointer (double dereference happen automatically when code accesses listnode, because reference object).

keep in mind rough equivalent, not one-for-one substitution: example, there no way pass array of listnode objects using listnodereference.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -