Is it possible to make a cycle in an immutalbe linked list
Suppose that we have to following structure in Java:
class List {
// we're immutable
final List next;
final int value;
public List(int value, List next) {
this.next = next;
this.value = value;
}
}
Scala has built-in support for uimmutable linked list. It would be:
val l = List(1, 2, 3) // immutable
So, is it possible to make a cycle in this kind of lists (immutable
singly-linked list). By cycle, I mean the following:
No comments:
Post a Comment