import javax.swing.JOptionPane; /** * COP 3337 Example * * @author Bill Kraynek */ public class Example7 { /** * @param args the command line arguments */ public static void main(String[] args) { Node start = new Node("This", new Node("is", new Node("example", new Node("sentence", null)))); display(start); start.next.next = new Node("an", start.next.next); display(start); String[] inserts = {"example", "sentee", "This"}; for (String string : inserts) { Node p = start; Node q = null; while (p != null && !p.data.equals(string)) { q = p; p = p.next; }// end while if (p != start) { q.next = new Node("insert", q.next); } else { start = new Node("insert", start); } display(start); }// 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 Example7