The Linked List program is available here: link
public String kthLastElement(int k) {
LinkedList L = this;
for(int i=1; i<k; i++) {
L=L.next;
}
StringBuffer sb = new StringBuffer();
while(L!=null) {
sb.append(L.data).append(", ");
L=L.next;
}
return sb.toString();
}
No comments:
Post a Comment