you have tag it as java. But few syntax are not support for java.
public int replace(String oldData, String newData )
{
int count = 0;
StringNode tmp = head;
while( tmp != null)
{
if(tmp.data.equals(oldData)
{
tmp.data = newData;
count = count + 1;
}
tmp = tmp.next;
}
return count;
}
Try this code in java. It should work. If the data is your own class, you have to override the equals method. Since it is string, it will work.