- #1
transgalactic
- 1,395
- 0
i was told to build a method for which if
we find the asked value in one of the links we
return the previous link
i have built a method that supposedly does it
the problem is that i was told that this code is wrong because
we need to check the "this" link seperatly from the FOR loop
why is that?
we find the asked value in one of the links we
return the previous link
i have built a method that supposedly does it
the problem is that i was told that this code is wrong because
we need to check the "this" link seperatly from the FOR loop
why is that?
Code:
public static Link find(Object x)
Link p;//current object
Link t;//previous object
for (p=Link;(p!=this);p=p.next, t=p)
{
if (p.data.equals(x)){
return t;
}
return null;
}
Last edited: