Check if array is sorted using recursion

Objec­tive:  Given an array of integer write a recursive solution to check if array is sorted.

Example:

int [] a = {1,2,3,4};
Output: true

int [] a = {1,2,3,4,2};
Output: false

Approach: This problem can easily be solved in single iteration by just comparing adjacent elements. Fun part is to write the recursive solution. Code is self explanatory.

Code:


Output:

true

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: