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

- 01-12-2013, 11:02 PMandy11Recursion with lists
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 ? - 01-13-2013, 12:11 AMFubarableRe: Recursion with lists
- 01-13-2013, 12:46 AMandy11Re: Recursion with lists
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 - 01-13-2013, 02:51 PMJosAHRe: Recursion with lists
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 - 01-13-2013, 11:59 PMandy11Re: Recursion with lists
Thanks Jos