I am trying to work on java for my next semester class that starts in a week. The first lab starts out with linklist. It ask to make a linklist with all odd numbers from 1-100. I have that so far. Where i am lost is the skipindex. I have looked at java.sun.com documentation and have found nothing about skipindex.
2) Set skipIndex to 1 or zero depending how you refer to the fist element in your list.
3) Using skipIndex find the next number to be used as the skipFactor.
4) Begin with the first node, set every element at skipFactor to zero.
5) Remove the nodes containing zeros from list
I am not asking for the answer just some sort of information on skipindex. I know how to remove duplicate numbers also. Just this skipindex thing is confusing me.
Here is my code so far. I know i have made it sloppy, but its just temp till I can get the hang of this linklist stuff.
2) Set skipIndex to 1 or zero depending how you refer to the fist element in your list.
3) Using skipIndex find the next number to be used as the skipFactor.
4) Begin with the first node, set every element at skipFactor to zero.
5) Remove the nodes containing zeros from list
I am not asking for the answer just some sort of information on skipindex. I know how to remove duplicate numbers also. Just this skipindex thing is confusing me.
Here is my code so far. I know i have made it sloppy, but its just temp till I can get the hang of this linklist stuff.
Code:
import java.util.*;
public class LinkedListTest
{
public static void main(
String[] args)
{ List a = new LinkedList();
int i = 1;
while (i < 100)
{
a.add(i);
i++;
i++;
}
ListIterator aIter = a.listIterator();
//aIter = a.iterator();
while (aIter.hasNext())
{ aIter.next();
aIter.next();
// skip one element
if (aIter.hasNext())
{ aIter.next();
// skip next element
aIter.remove();
// remove that element
}
}
System.out.println(a);
}
}