0
How can we append a given string to the end of a list?
14 Antworten
+ 2
Sin There isnt difference... A list contains an attribute pointing to first elemtent and any element contain the next one... Then, you have to go to last element (which has next attribute to null) and append to it (eg. Set his next attribute) a new element... This works for any type
+ 1
Sin Then you have to implement a custom list? Its not clear from description
+ 1
Sin Start with implements StringElement... You know how list works?
0
KrOW can't find it there. It's not a Boolean..."private StringListElement first;"
"public void append(String string) "
https://code.sololearn.com/c8ZKMBW2arLd/?ref=app
0
there are setters and getters given. I have to implement the method.... to get the given string.
0
we can't use this:(
0
0
We can't use implements... we have to use getString() getNext() getPrev() with nodes etc...
but idk how to start I know how to make it with int value but not with strings.
KrOW
0
Sin i mean, you know how list data structure works? I understood that you have to implement yourself without use java premade types for this...
0
KrOW for int data/value yes. for string not really😔😔
0
Sin what you mean with "i know hpw to make it with int but not with strings"?? Whats the problem??
0
i know how to append given int value at the end of list but Not Strings.. KrOW
addlast=append
public void append(String string) { StringListElement elem = new StringListElement(); defter.setString(string); if(first==null) { this.first=elem;} else { StringListElement temp=first; while(temp.getNext()!=null) { temp=temp.getNext(); } temp.setNext(elem); } }
it says it ist wring
0
elem.setString(string)*