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-13-2013, 12:02 AMandy11Recursion 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, 01:11 AMFubarableRe: Recursion with lists
- 01-13-2013, 01: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, 03: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-14-2013, 12:59 AMandy11Re: Recursion with lists
Thanks Jos