I have created a linked-list class called "SList", which allows an empty linked-list to be created. The method "insertFront" inserts an object at the front of the list and increases the size. Below, in the main class, I have created an SList object and added two strings to the list. I would like to print this list. I attempted to create an iterator object imported from java.util, but the compiler is giving me a red underline under "Iterator". Why am I getting this error? How should I print this linked-list?
public class SList
{
private SListNode head;
private int size; //number of items in the list
public SList() //constructor, empty list
{
head = null;
size = 0;
}
public void insertFront(Object item)
{
head = new SListNode(item, head);
size++;
}
}
import java.util.*;
public class LinkMain
{
public static void main(String[] args)
{
String apples = "apples";
String oranges = "oranges";
SList x = new SList();
x.insertFront(apples);
x.insertFront(oranges);
Iterator iter = x.Iterator();
}
}