/**
 * Name: Travis McGaha
 *
 * PennKey: tqmcgaha
 *
 * Execution: java Recursive
 *
 * Description: A program fillled with various examples of writing recursive
 * code. Currently just prints 5 stars.
 */
public class Recursive {
    // iterative solution
    /*
     * Prints num number of stars
     * Input: the number of stars to print
     */
    public void printStarsLoop(int num) {
        // stop when we've printed num times
        for (int i = 0; i < num; i++) {
            // print a star
            System.out.print("*");
        }
    }

    // Recursive solution
    /*
     * Prints num number of stars
     * Input: the number of stars to print
     */
    public static void printStarsRecursive(int num) {
        if (num <= 0) {
            // do nothing
            return;
        } else {
            // print a single star
            System.out.print("*");
            // Pass the problem (now slightly reduced)
            // to another invocation of the function to handle
            // Note how we decrement num
            printStarsRecursive(num - 1);
        }
    }

    /*
     * multiplies two ints
     *
     * Inputs: ints x and y, assumes that x >= 1
     * Output: the product of the inputs
     */
    public static int multiply(int x, int y) {
        if (x == 1) {
            return y;
        }
        return y + multiply(x - 1, y);
    }

    /**
     * returns the length of the chain rooted at n
     * 
     * Inputs: n, a variable containing a reference to the head of some linked
     * sequence of nodes.
     * Output: the length of the chain rooted at n
     */
    public static int length(Node n) {
        if (n == null) {
            return 0;
        } else {
            return 1 + length(n.next);
        }
    }

    /*
     * gets the length of a string
     *
     * Input: string to get the length of. Assumes that str is not null.
     * Output: length of input string
     */
    public static int stringLength(String str) {
        if (str.equals("")) {
            return 0;
        }
        return 1 + stringLength(str.substring(1));
    }

    /*
     * prints each character of a string
     *
     * Input: string to print the characters of. Assumes that str is not null.
     */
    public static void printChars(String str) {
        if (str.equals("")) {
            return;
        } else {
            System.out.println(str.charAt(0));
            printChars(str.substring(1));
        }
    }

    /*
     * prints each character of a string in reverse order.
     *
     * Input: string to print the characters of. Assumes that str is not null.
     */
    public static void printCharsReverse(String str) {
        if (str.equals("")) {
            return;
        } else {
            printChars(str.substring(1));
            System.out.println(str.charAt(0));
        }
    }

    // Returns true if the string is a palindrome; false otherwise.
    public static boolean isPalindrome(String s) {
        return false;
    }

    // recursively print all Nodes in the sequence rooted at n
    public static void printNodes(Node n) {
        if (n == null) {
            return;
        } else {
            System.out.println(n.data);
            printNodes(n.next);
        }
    }

    // return the index of the node in the sequence rooted at
    // n where target appears, or -1 if the target is not present
    public static int linearSearchNodes(Node n, int target) {
        return 0;
    }

    /*
     * returns the sum of the values of all nodes in the sequence rooted at n
     */
    public static int sumNodes(Node n, int target) {
        return 0;
    }

    // return the index of the position in the array arr
    // where target appears, or -1 if the target is not present
    public static int linearSearchArray(int[] arr, int target, int idx) {
        return 0;
    }

    public static void main(String[] args) {
        printStarsRecursive(5);
        Node head = new Node(1100, null);
        head.next = new Node(1200, null);
        head.next.next = new Node(1600, null);
        head.next.next.next = new Node(1210, null);
        head.next.next.next = new Node(2400, null);
    }

}
