import javax.swing.JOptionPane; /** * COP 3337 Example * * @author Bill Kraynek */ public class Example8 { /** * @param args the command line arguments */ public static void main(String[] args) { Node start = new Node(); start.next = new Node("This", new Node("is", new Node("example", new Node("sentence", null)))); display(start.next); start.next.next.next = new Node("an", start.next.next.next); display(start.next); String[] inserts = {"example", "sentee", "This"}; for (String string : inserts) { Node p = start; while (p.next != null && !p.next.data.equals(string)) { p = p.next; }// end while p.next = new Node("insert", p.next); display(start.next); }// end for }// end main static void display(Node list) { Node p = list; String out = ""; while (p != null) { out += p.data + " "; p = p.next; }// end while out = out.substring(0, out.length() - 1) + ".\n"; out += "List = " + list + "\n"; JOptionPane.showMessageDialog(null, out); }// end display static class Node { String data; Node next; Node() { } Node(String data, Node next) { this.data = data; this.next = next; }// end constructor public String toString() { return "(" + data + " , " + next + ")"; }// end toString }// end Node }// end Example8