Код: Выделить всё
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
LinkedList cannot be resolved to a type
LinkedList cannot be resolved to a type
LinkedList cannot be resolved to a type
at StacksQLLExample.main(StacksQLLExample.java:23)
Код: Выделить всё
import java.util.ListIterator;
import java.util.Queue;
import java.util.Stack;
import java.util.LinkedList;
public class StacksQLLExample
{
public static void main(String[] args)
{
Stack s = new Stack();
s.push(1);
s.push(5);
s.push(52);
s.push(Integer.MAX_VALUE);
System.out.println(s);
while (!s.isEmpty())
{
System.out.println("peek: "+ s.peek());
//System.out.println(s);
System.out.println("pop: "+ s.pop());
}
Queue q = new LinkedList();
q.add(1);
q.add(5);
q.add(52);
q.add(Integer.MAX_VALUE);
System.out.println(q);
while (!s.isEmpty())
{
System.out.println("peek: "+ q.peek());
System.out.println("delete: "+ q.remove()) ;
}
System.out.println();
LinkedList ll = new LinkedList();
ll.addFirst("D");
ll.addLast("H");
ll.add("R"); // same as addLast
ll.addLast("T");
System.out.println(ll);
ListIterator iter = ll.listIterator(); // puts iter at the beginning of the list
while (iter.hasNext())
{
String str = iter.next(); // returns what is to the left of the iter
str += str;
System.out.println(str);
}
if (iter.hasNext()) iter.next(); // iter is at the end of the list
iter = ll.listIterator(); // back to the beginning
while (iter.hasNext())
{
String str = iter.next();
if (str.equals("D"))
{
iter.add("J");
}
}
System.out.println(ll);
iter.remove();
System.out.println(ll);
iter.add("K");
System.out.println(ll);
// This creates an error because the iter never moved over with the other element
// You also can't remove what you just added
// iter.remove();
// System.out.println(iter); // prints a memory reference
}
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... in-eclipse