/home/caleb/ASDV-Java/Semester 3/Assignments/Lab_CalebFontenot_MaximumOrderedString/src/main/java/edu/slcc/asdv/caleb/lab_calebfontenot_maximumorderedstring/FindMax.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

/**
 *
 * @author caleb
 */
public class FindMax {
    public static String findMax(String input) {
        int iterationCount = 0;
        ArrayList<String> possibleSubStr = new ArrayList<>();
        String currentStr = "";
        for (int i = 0; i < input.length() -2; ++i) {
            currentStr = input.charAt(i) + "";
            for(int j = i + 1; j < input.length() -1; ++j) {
                iterationCount++;
                if (input.toLowerCase().charAt(i) < input.toLowerCase().charAt(j)) {
                    currentStr += input.charAt(j);
                } else {
                    possibleSubStr.add(currentStr);
                    break;
                }
            }
        }
        System.out.println("Iteration count: " + iterationCount);
        System.out.println(possibleSubStr);
        Collections.sort(possibleSubStr, new CompareSize());
        return possibleSubStr.get(0);
    }
    public static void main(String[] args)
    {
        //System.out.print("Enter a string: ");
        //Scanner input = new Scanner(System.in);
        String inputString = "abcdabcdefgzabcdefadcdefab";
        //input.nextLine();
        System.out.print("The maximum sorted subString is: ");
        System.out.println(findMax(inputString));
    }
}