Java Self-Programmed Singly-Linked-List in Linked-List -


at least me, have tricky exercise university. task program singly-linked-list kind of methods. far easy, challenge store these singly-linked-lists afterwards in linked-list. in following see implementation of singly-linked-list runs smoothly:

public class liste {  listenelement first; listenelement last; listenelement current; int count;  public liste() {     first = null;     last = null;     current = null;     count = 0; }  // methods... 

the single-linked list consists of list elements implemented in following:

public class listenelement {  string content; listenelement next;  public listenelement(string content, listenelement next) {     this.content = content;     this.next = next; }  //methods... 

here problem:

linkedlist<liste> zeilen = new linkedlist<>(); liste zeile1 = new liste(); liste zeile2 = new liste();  zeile1.addbehind("hello"); zeile1.addbehind("world"); zeile2.addbehind("hello"); zeile2.addbehind("world");  zeilen.add(zeile1); zeilen.add(zeile2);  system.out.print(zeilen.get(1)); //printed: listen.liste@4aa298b73 instead of hello world. 

thank in advance help!

system.out.print(zeilen.get(1)); 

//printed: listen.liste@4aa298b73 instead of hello world.

that's output of default object#tostring. if want different output liste class, need override tostring provide different output.

for example: if wanted liste#tostring return comma-delimited list of tostrings of contents:

@override public string tostring() {     stringbuffer sb = new stringbuffer(10 * this.count); // complete guess     listenelement el = this.first;     while (el != null) {         sb.append(el.content.tostring());         el = el.next;         if (el != null) {             sb.append(", ");         }     }     return sb.tostring(); } 

(i'm making assumptions there how list class works, based on code showed...)


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -