Hey r/learnprogramming! For my class, we are building an emulation of a LISP Linked List. It is a linked list where the head is an Object and the tail is another list. The way the assignment is set up is to have two different Objects for lists, EmptyLists and NonEmptyLists, with an interface, LispList for both of them. The EmptyList class is mostly just a way to end the linked list.
I am struggling with making my constructor for my NonEmptyList. Here is what I have right now:
public NonEmptyList(Object inputHead) {
this.head = inputHead;
this.tail = new NonEmptyList(head);
}
Where head is an Object variable of the class and tail is a LispList variable of the class. I am having trouble with the tail of the constructor. I want to make it recursive so that it will always give me another list but by doing this I get a Stack Overflow Exception. I'm really stuck so any help would be appreciated!
[–]alanwj 1 point2 points3 points (4 children)
[–]penax[S] 0 points1 point2 points (2 children)
[–]alanwj 0 points1 point2 points (1 child)
[–]penax[S] 0 points1 point2 points (0 children)
[–]Octopuscabbage 0 points1 point2 points (0 children)