public bool add(int e)
{
if(head == null)
{
Node n = new Node
{
element = e
};
head = n;
return true;
}
Node t = head;
if(t.next == null)
{
if(t.element == e)
{ return false; }
Node n = new Node
{
element = e
};
t.next = n;
return true;
}
t = t.next;
this.add(e);
return true;
}
This is a code to add a new node in set. No duplicated values allowed. There is Main Class called Sets and one inner class called Nodes. I know Node t = head; is creating a problem is there anyway to make this recursive? Even passing extra optional parameters doesn't help.