protected static boolean isStringListSorted(List data, boolean ascending) {
if (ascending) {
for (int i = 0; i < data.size() - 1; i++) {
if (data.get(i).compareTo(data.get(i + 1)) > 0) {
System.out.println(data.get(i) + " AND " + data.get(i + 1) + " Not in ascending order");
return false;
}
}
} else {
for (int i = 0; i < data.size() - 1; i++) {
if (data.get(i).compareTo(data.get(i + 1)) < 0) {
System.out.println(data.get(i) + " AND " + data.get(i + 1) + " Not in descending order");
return false;
}
}
}
return true;
}
public static boolean isIntegerListSorted(int[] data, boolean ascending) {
if (ascending) {
for (int i = 0; i < data.length; i++) {
if (data[i] < data[i+1]) {
System.out.println(data[i] + " AND " + data[i+1] + " Not in ascending order");
return false;
}
}
} else {
for (int i = 0; i < data.length; i++) {
if (data[i] > data[i+1]) {
System.out.println(data[i] + " AND " + data[i+1] + " Not in descending order");
return false;
}
}
}
return true;
}
if (ascending) {
for (int i = 0; i < data.size() - 1; i++) {
if (data.get(i).compareTo(data.get(i + 1)) > 0) {
System.out.println(data.get(i) + " AND " + data.get(i + 1) + " Not in ascending order");
return false;
}
}
} else {
for (int i = 0; i < data.size() - 1; i++) {
if (data.get(i).compareTo(data.get(i + 1)) < 0) {
System.out.println(data.get(i) + " AND " + data.get(i + 1) + " Not in descending order");
return false;
}
}
}
return true;
}
public static boolean isIntegerListSorted(int[] data, boolean ascending) {
if (ascending) {
for (int i = 0; i < data.length; i++) {
if (data[i] < data[i+1]) {
System.out.println(data[i] + " AND " + data[i+1] + " Not in ascending order");
return false;
}
}
} else {
for (int i = 0; i < data.length; i++) {
if (data[i] > data[i+1]) {
System.out.println(data[i] + " AND " + data[i+1] + " Not in descending order");
return false;
}
}
}
return true;
}