// Guide to Data Structures
// Section 5.9
// Copyright 2018, by J.T. Streib and T. Soma
import java.util.*;
class PrintRecStr {
public static void main(String[] args) {
Scanner scanner;
scanner = new Scanner(System.in);
String str;
NodeGeneric<String> head,newN;
head = null;
System.out.println();
System.out.print("Enter \"stop\" to stop: ");
str = new String(scanner.next());
while(!str.equals("stop")) {
newN = new NodeGeneric<String>(str);
newN.setNext(head);
head=newN;
System.out.print("Enter \"stop\" to stop: ");
str = scanner.next();
}
System.out.println();
printRecursive(head);
}
public static void printRecursive(NodeGeneric<String> ref) {
if(ref != null) {
System.out.println(ref.getData());
printRecursive(ref.getNext());
}
}
}
public class NodeGeneric<T> {
private T data;
private NodeGeneric<T> next;
public NodeGeneric() {
this(null);
}
public NodeGeneric(T data) {
this.data = data;
next = null;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public NodeGeneric getNext() {
return next;
}
public void setNext(NodeGeneric<T> next) {
this.next = next;
}
}