So i've made a Node class :
public class IntNode
{
private int _value;
private IntNode _next;
public IntNode(int v, IntNode n)
{
_value = v; _next = n;
}
public int getValue()
{
return _value;
}
public IntNode getNext()
{
return _next;
}
public void setValue(int v)
{
_value = v;
}
public void setNext(IntNode n)
{
_next = n;
}
}
and a class with some functions, from them are the isMember (true if num is a member of the list), and a subset which supposed to return true if "other" is a sub of the object :
public boolean isMember (int num)
{
if (_head !=null)
{
if (_head.getValue()==num)
return true;
else{
IntNode member = _head;
while (member.getNext() !=null){
if (member.getNext().getValue()==num) {
return true;
}
}
}
}
return false;
}
public boolean subSet (Set other)
{
IntNode number = _head;
for (int i=0; i<other.numOfElements(); i++)
{
if (isMember(number.getValue())==false)
return false;
number.getNext();
}
return true;
}
and i run my simple tester to see if sub works correctly but when it reaches num 9, it get stuck in endless loop. why?
/*# subSet */
s1 = new Set();
s1.addToSet(1); s1.addToSet(3); s1.addToSet(9); s1.addToSet(17);
s2 = new Set();
s2.addToSet(1);
System.out.println(s1.subSet(s2));