Markou is absolutely insane

This commit is contained in:
2024-01-26 15:28:42 -06:00
parent aa46f43ea5
commit aef4bcc29c
36 changed files with 1373 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ package edu.slcc.asdv.caleb.lab_calebfontenot_maximumorderedstring;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
/**
*
@@ -21,7 +22,7 @@ public class FindMaxOrderedSubstring {
outputString += input.charAt(i);
}
if (input.charAt(i) > outputString.charAt(j)) {
++j;
System.out.println(++j);
outputString += input.charAt(i);
}
}
@@ -29,6 +30,9 @@ public class FindMaxOrderedSubstring {
}
public static void main(String[] args) {
System.out.println(findMaxOrderedSubString("Welcome!"));
Scanner input = new Scanner(System.in);
System.out.print("Enter a string: ");
String inputStr = input.nextLine();
System.out.println(findMaxOrderedSubString(inputStr));
}
}

View File

@@ -0,0 +1,105 @@
/*
* 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;
/**
*
* @author caleb
*/
import java.util.Comparator;
public class GenericMergeSort {
public static <E extends Comparable<E>> void mergeSort(E[] list)
{
mergeSort(list,
new Comparator<E>() {
@Override
public int compare(E e1, E e2)
{
return ((Comparable<E>) e1).compareTo(e2);
}
});
}
static int recursiveCallCount = 0;
public static <E> void mergeSort(E[] list,
Comparator<? super E> comparator)
{
if (list.length > 1) {
recursiveCallCount++;
// Merge sort the first half
E[] firstHalf = (E[]) new Object[list.length / 2];
System.arraycopy(list, 0, firstHalf, 0, list.length / 2);
mergeSort(firstHalf, comparator);
// Merge sort the second half
int secondHalfLength = list.length - list.length / 2;
E[] secondHalf = (E[]) new Object[secondHalfLength];
System.arraycopy(list, list.length / 2,
secondHalf, 0, secondHalfLength);
mergeSort(secondHalf, comparator);
// Merge firstHalf with secondHalf
E[] temp = merge1(firstHalf, secondHalf, comparator);
System.arraycopy(temp, 0, list, 0, temp.length);
}
}
private static <E> E[]
merge1(E[] list1, E[] list2, Comparator<? super E> comparator)
{
E[] temp = (E[]) new Object[list1.length + list2.length];
int current1 = 0; // Index in list1
int current2 = 0; // Index in list2
int current3 = 0; // Index in temp
while (current1 < list1.length && current2 < list2.length) {
if (comparator.compare(list1[current1], list2[current2]) < 0) {
temp[current3++] = list1[current1++];
} else {
temp[current3++] = list2[current2++];
}
}
while (current1 < list1.length) {
temp[current3++] = list1[current1++];
}
while (current2 < list2.length) {
temp[current3++] = list2[current2++];
}
return temp;
}
public static void main(String[] args)
{
Integer[] list
= {
2, 3, 2, 5, 6, 1, -2, 3, 14, 12
};
mergeSort(list);
System.out.println("number of recursive calls: " + recursiveCallCount);
recursiveCallCount = 0;
for (int i = 0; i < list.length; i++) {
System.out.print(list[i] + " ");
}
System.out.println();
String[] list1
= {
"ABC", "abc", "abm", "Anf", "Good", "Bad", "nice"
};
mergeSort(list1, (s1, s2) -> s1.compareToIgnoreCase(s2));
System.out.println("number of recursive calls: " + recursiveCallCount);
recursiveCallCount = 0;
for (int i = 0; i < list1.length; i++) {
System.out.print(list1[i] + " ");
}
}
}

View File

@@ -0,0 +1,56 @@
/*
* 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;
/**
*
* @author caleb
*/
public class JudeFindMax {
public static void main(String[] args) {
System.out.println(consecLetters("abcabcdgabxy"));
System.out.println(consecLetters("abcabcdgabmnsxy"));
System.out.println(consecLetters("abchjsfhajshfhijklmnopqjfaksfhkajhsf"));
System.out.println(consecLetters("hnafffgardghikortmmnmnmn"));
}
public static String consecLetters(String input)
{
String consec = "";
String maxConsec = "";
for (int i = 1; i < input.length(); i++) //n - 1
{
//If two in order
if (input.charAt(i) > input.charAt(i - 1))
{
//If length is zero then add previous as well
if (consec.length() == 0)
consec += input.charAt(i - 1);
consec += input.charAt(i);
}
//If not in order
else
{
//Check current consec length against maximum length
if (consec.length() > maxConsec.length())
{
//set new max
maxConsec = consec;
}
consec = "";
}
}
//Check current consec length against maximum length
if (consec.length() > maxConsec.length())
{
//set new max
maxConsec = consec;
}
return "Most letters found in order: " + maxConsec;
}
}