Hi, I have to do program that uses a for loop to traverse a linked list. I have 99% of the program done and ready to go but our professor wanted us to use a specific loop which is the loop on line 31. I don't understand what b is suppose to be. like... how would i declare b and what would it be declared as... I don't think its an iterator. ill post my code below that so you can get an idea of what i'm trying to do and what i'm missing.
import java.util.*;
public class homeWorkThree{
public static void main(String[] args)
{
LinkedList <Integer>list = new LinkedList<Integer>();
int one=1, two=2, three=3, four=4, five=5, n=0;
list.add(one);
list.add(two);
list.add(three);
list.add(four);
list.add(five);
occur(list,n=4);
boolean trueOrFalse = occur(list, n);
if(trueOrFalse==true)
System.out.println(trueOrFalse+": "+n+" does occur in the list");
else
System.out.println(trueOrFalse+": "+n+" does NOT occur in the list");
occur(list,n=9);
boolean trueOrFalseTwo = occur(list, n);
if(trueOrFalseTwo==true)
System.out.println(trueOrFalseTwo+": "+n+" does occur in the list");
else
System.out.println(trueOrFalseTwo+": "+n+" does NOT occur in the list");
}
public static boolean occur(LinkedList <Integer>list, int n){
boolean isItTrue = false;
for(b=list;b != null;b=b.rest)
System.out.print(b.first);
for(int i = 0; i < list.size(); ++i){
if(list.get(i)==n)
isItTrue=true;
else{}
}
return isItTrue;
}
}