java - Reversing order of recursive output -
i'm making singly-linked queue cs assignment , 1 supposed implement tostring method displays elements such: in -> [ “data 1” , “data 2” , “data 3” ] -> out.
however, first node 1 thats been there latest, method returns oldest element next in , newest out, think reverse order.
here's code:
public string tostring() { if(value == null){ return ""; } else if(next == null){ return "\"" + value + "\""; } else { return "\"" + value + "\" ; " + next.tostring(); } }
is there way can reverse order?
thanks
Comments
Post a Comment