import java.io.File;
import java.util.Comparator;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;

public class LinkedListExample {
    
    public LinkedListExample() {
        List<String> words = new MySingleLinkedList<String>();
        //List<String> words = new MyDoubleLinkedList<String>();
        try {
            Scanner in = new Scanner(new File("src/LinkedListExample.java"));
            in.useDelimiter("[^a-zA-Z]+");
            while( in.hasNext() ) {
                while( in.hasNext() ) {
                    String aWord = in.next();
                    words.add(aWord);
                } // end while
            } // end while
        } catch(Exception e) {
            e.printStackTrace();
        } // end try/catch
        words.add("Test");
        String out = "";
        ListIterator<String> itr = words.listIterator();
        while( itr.hasNext() ) {
            out += itr.next() + "\n";
            //itr.remove();
        }
        JTextArea outArea = new JTextArea(30,40);
        outArea.setText(out+words);
        JOptionPane.showMessageDialog(null,new JScrollPane(outArea));
        out = "";
        while( itr.hasPrevious() ) {
            out += itr.previous() + "\n";
            itr.remove();
        }// end while
        words.add("Test");
        outArea.setText(out+words);
        JOptionPane.showMessageDialog(null,new JScrollPane(outArea));
    } // end constructor
    
    public static void main(String[] args) {
        new LinkedListExample();
        System.exit(0);
    } // end main
    
} // end LinkedListExample






