import java.util.ArrayList;

public class HelloWorld {


    public static void insertionSort(ArrayList<String> arr) {
        int n = arr.size();
        // Start from the second element (index 1)
        for (int i = 1; i < n; i++) {
            String key = arr.get(i); // The element to be inserted
            int j = i - 1;    // Index of the element before the key

            // Move elements of arr[0..i-1], that are greater than key,
            // to one position ahead of their current position
            while (j >= 0 && key.compareTo(arr.get(j)) < 0) {
                arr.set(j+1, arr.get(j));
                j = j - 1;
            }
            arr.set(j+1,key);
            //arr[j + 1] = key; // Insert the key in its correct position
        }
        
    }

     public static void printStudent(ArrayList<Student> str){
        // words.set(2, "pig");
        for(Student s : str){
            StdOut.println(s);
        }
    }

    public static void printStr(ArrayList<String> str){
        // words.set(2, "pig");
        for(String s : str){
            StdOut.println(s);
        }
    }

    public static boolean linearSearchStudent(ArrayList<Student> students, int key){
        //boolean found = false;
        for(Student s : students){
            if(s.getID() == key){
                return true;
            }
        }
        return false;
    }

    public static void insertionSortStudent(ArrayList<Student> arr) {
        int n = arr.size();
        // Start from the second element (index 1)
        for (int i = 1; i < n; i++) {
            Student key = arr.get(i); // The element to be inserted
            int j = i - 1;    // Index of the element before the key

            // Move elements of arr[0..i-1], that are greater than key,
            // to one position ahead of their current position
            while (j >= 0 && key.toString().compareTo(arr.get(j).toString()) < 0) {
                arr.set(j+1, arr.get(j));
                j = j - 1;
            }
            arr.set(j+1,key);
            //arr[j + 1] = key; // Insert the key in its correct position
        }
        
    }

    public static void swapStudent(ArrayList<Student> students, int n1, int n2){
        Student s1 = students.get(n1);
        students.set(n1, students.get(n2));
        students.set(n2, s1);
    }

    public static Student max(ArrayList<Student> students){
        Student maxStudent = students.get(0);

        for(int i = 1; i < students.size(); i++){
            Student currStudent = students.get(i);
            if(maxStudent.getGPA() < currStudent.getGPA()){
                maxStudent = currStudent;
            }
        }

        return maxStudent;
    }

    public static void main(String[] args) {        
        
        Student s1 = new Student("Natalie", "Milonas");
        Student s2 = new Student("Nicholas", "Milonas");

        ArrayList<Student> students = new ArrayList<Student>();
        students.add(new Student("Zoe", "Milonas"));
        students.add(s1);
        students.add(0,s2);
        
        
        //insertionSortStudent(students);

        printStudent(students);

       /* Student m = max(students);*/
        StdOut.println(students.get(students.size()-1));



        /*
        if(linearSearchStudent(students, 1004)){
            StdOut.println("Found");
        }else{
            StdOut.println("Not Found");
        }*/

        //StdOut.println(s1);
        //StdOut.println(s2);
        /*ArrayList<String> words = new ArrayList<String>();

        
        words.add("elephant");
        words.add("dog");
        words.add("horse");
        words.add("frog");
        words.add("cat");
        words.add("pig");*/
       /* String temp = words.get(2);
        words.set(2, words.get(5));
        words.set(5,temp);
        
        String r = words.remove(4);
       StdOut.println(r);*/
       // words.set(2, "pig");
        /*for(String s : words){
            StdOut.println(s);
        }*/
       /*insertionSort(words);
        printStr(words);
        */

        /*int count = 0;
        
        for(int i = 0; i < words.size(); i++){
            String str = words.get(i);
            //arr[i].length()
            //words.get(i).length()
            if(str.length() == 3){
                count++;
            }
        }
        StdOut.println(count);

        */


       /* ArrayList<String> names = new ArrayList<String>();
        names.add("Rachel");
        names.add("Julia");
        names.add(0, "Josh");
        names.add("Tim");
        names.add("Nate");
        names.add(0, "Connor");
       // names.remove(3);
        StdOut.println(names.size());

        for(int i = 0; i < names.size();i++){
            StdOut.println(names.get(i)); //array[i]
        }
    */
    /*
        ArrayList<Integer> nums = new ArrayList<Integer>();
        nums.add(7);
        nums.add(7);
        for(int i = 0; i < 15; i++){
            int n = (int)(Math.random() * 10) + 1;
            nums.add(n);
        }

        StdOut.println("nums size " + nums.size());


        for(int i = 0; i < 30; i++){
            int n = (int)(Math.random() * 10) + 1;
            nums.add(n);
        }
        StdOut.println("Second set of numbers");
        StdOut.println("nums size " + nums.size());
        int count = 0; */
        /*for(int i = 0; i < nums.size();i++){
            if(nums.get(i) == 7)
            {
                count++;
                nums.remove(i);
                i--;
            }
            //StdOut.println(nums.get(i)); //array[i]
        }*/
       /*int z = 0;
       while(z< nums.size()){
        if(nums.get(z) == 7){
            nums.remove(z);
            count++;
        }else{
            z++;
        }
       }


        StdOut.println(count);
        StdOut.println("nums size " + nums.size());
        
        for(int i = 0; i < nums.size();i++){
            StdOut.println(nums.get(i)); //array[i]
        }*/
        //array - .length
        //String - .length()
        //ArrayList - .size()


        

    }
}