package eecs2030.lab6; import java.awt.Color; import java.util.List; /** * A utility class containing recursive methods. * * @author EECS2030 Fall 2016 * */ public class Recursion { // DON'T ADD ANY STATIC FIELDS; YOU DON'T STATIC FIELDS AND YOUR METHODS // WON'T WORK CORRECTLY IF YOU USE STATIC FIELDS private Recursion() { // empty by design } /** * Return the sum of the integers 1 through n where n is a strictly positive integer. * Note that the sum might overflow if n is too large; this method does not * check if the sum overflows (i.e., it's the client's problem). * * @pre n is greater than 0 * * @param n * a strictly positive number * @return the sum 1 + 2 + ... + n */ public static int sum(int n) { } /** * Returns a new string equal to the reversal of string s. The reversal of * the empty string is equal to the empty string. * * @pre s is not null * * @param s * a string * @return a string equal to the reversal of s */ public static String reverse(String s) { } /** * Returns the minimum element in the list t. This method does not modify * the list t. * * @pre t.size() is greater than 0 * * @param t * a non-empty list * @return the minimum element in t */ public static int min(List t) { } /** * Downsample a picture n times by a factor of 2 using * recursion. See the lab problem for a description of downsampling. * * @pre the width and height of the picture are both multiples of 2 to the * power n * * @pre1 n is greater than or equal to zero * * @param p * the picture to downsample * @param n * the number of times to downsample the picture by a factor of 2 * @return the downsampled picture */ public static Picture downsample(Picture p, int n) { } /** * Binary search for the string s in a list t. If * s is in the list, then this method returns the index of the * location of s in t; otherwise, this method * returns the index where s would be located if it were to be * inserted into the list t. * *

* This method does not modify the list t. * * @pre t.size() is zero or more * @pre1 t is in sorted order * @pre2 t has no duplicate elements * * @param s * a string * @param t * a list * @return the index of s if s is in the list; otherwise, returns the index * where s would be located if it were to be inserted into the list */ public static int bsearch(String s, List t) { } public static void main(String[] args) { // RUN THIS TO TEST downsample Picture p = new Picture("snowflake.jpg"); p.show(); downsample(p, 1).show(); downsample(p, 2).show(); downsample(p, 3).show(); } }