1. Member
Join Date
Jan 2013
Posts
3
Rep Power
0

## Recursion 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 ?

2. ## Re: Recursion with lists

Originally Posted by andy11
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 ?

Please show us what you have so far as well as how it isn't working.

3. Member
Join Date
Jan 2013
Posts
3
Rep Power
0

## Re: 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

4. ## Re: 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

5. Member
Join Date
Jan 2013
Posts
3
Rep Power
0

## Re: Recursion with lists

Thanks Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•