Я пытаюсь получить связанный список реализации алгоритма стека-поп. Вот полный код. Код на самом деле взят из курса Алгоритм, часть 1 в Coursera.
public class LinkedStackOfString {
private Node first = null;
private class Node {
String item;
Node next;
}
public boolean isEmpty() {
return first == null;
}
public void push(String item) {
Node oldfirst = first;
first = new Node();
first.item = item;
first.next = oldfirst;
}
public String pop() {
String item = first.item;
first = first.next;
return item;
}
public static void main(String[] args) {
LinkedStackOfString stack = new LinkedStackOfString();
while (!System.in.isEmpty())
{
String s = System.in.readString();
if (s.equals("-")) System.out.println(stack.pop());
else stack.push(s);
}
}
}
Я помещаю полный текст сообщения об ошибке. Я получаю сообщение об ошибке, подобное этому:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method isEmpty() is undefined for the type InputStream
The method readString() is undefined for the type InputStream
at linkedList/linkedList.LinkedStackOfString.main(LinkedStackOfString.java:30)
Может кто-нибудь объяснить, что происходит? Я новичок в Java