I'm currently studying for a test and I don't really understand linked list that well. I was wondering if anyone could explain a few lines of code to me.
class Node{
Node next, previous;
final int value;
Node(int v){
value = v;
}
}
public class Linked{
Node start = null, end = null;
// Add a node on the end
void append(int v){
Node n = new Node(v);
if (start == null){
start = end = n;
return;
}
end.next = n;
n.previous = end;
end = n;
}
// Add a node to the front
void prepend(int v){
Node n = new Node(v);
if (start == null){
end = start = n;
return;
}
n.next = start;
start.previous = n;
start = n;
}
}
The lines that I need explained are the last 3 lines in the append and the prepend methods. The comments explain the purpose of each of the methods, but I don't understand what is actually being done in those lines of code. Thanks in advance.