Hi guys , can u help me? im suppose to write a boolean method
public static boolean isSorted(List l)
that returns true when a list is sorted....can u help me ?
Printable View
Hi guys , can u help me? im suppose to write a boolean method
public static boolean isSorted(List l)
that returns true when a list is sorted....can u help me ?
public static boolean isSorted(List l) {
if (l.isEmpty())
{
return true;
}
else if(l.tail().isEmpty())
{
return true;
}
else if (now here is my problem i want to check the head of the list with the next element of the tail and check if l.head() is lower than the first element of the tail and so on,here is my problem i dont understand how to do it recursively
Try to say it in words: if the list is empty or the list's tail is empty, the list is sorted, otherwise if the list's head isn't larger than than the head of the tail of the list and the list's tail is sorted the the entire list is sorted.
The phrase in italics is the recursion step.
kind regards,
Jos
Thanks Jos