/* *****************************************************************************
  *
  *  Description: A circularly linked list of words that supports insertion
  *  without copying any elements.
  * 
  *  Remarks:
  *   - This code is based on Exercise 4.3.51.
  *
 **************************************************************************** */

public class CircularQuote {

    // the first card in the circular linked list
    private Node start;

    // node stores a word and a reference to the next node
    private class Node {
        private String word; // word in a sentence
        private Node next;   // next word

        private Node(String word) {
            this.word = word;
            this.next = null;
        }
    }
   
    // creates an empty quote
    public CircularQuote() {
        ______________;
    }
   
    // adds a word to the end of the quote
    public void addWord(String word) {
        ______________;

        // degenerate case for empty quote
        if (____________________) {

            ______________;
        } 
        else {        
            // traverse linked list until you find the last node
            ______________;

  
            // insert new word
            ______________;

        }
    }
   
    // number of words in the quote
    public int count() {
        ______________;
    }

    // return the ith word where i = 1 is first word in quote
    public String getWord(int i) {
        // check for fewer than i words in quote or invalid index
        if (count() < i || i <= 0) {
            throw new RuntimeException("index out of bounds");
        }
        ______________;
       
    }

    // insert specified word after the ith word (i = 1 is the first word)
    public void insertWord(int i, String word) {
        // check for fewer than i words in quote or invalid index
        if (count() < i || i <= 0) 
            throw new RuntimeException("index out of bounds");

        // make Node for the new word
        ______________;


        // find the ith card
        ______________;


        // insert between ith card its current next
        ______________;

    }

    // string representation of the entire quote
    public String toString() {
        ______________;
    }

    // test client
    public static void main(String[] args) { 
        CircularQuote quote = new CircularQuote();
        quote.addWord("A");
        quote.addWord("rose");
        quote.addWord("is");
        quote.addWord("a");
        quote.addWord("rose.");
        StdOut.println(quote);
        StdOut.println(quote.count());
        StdOut.println(quote.getWord(2));
        quote.insertWord(3, "just");
        StdOut.println(quote);
        StdOut.println(quote.count());
    }
}
