check array is sorted recursion
#include <iostream>
using namespace std;
bool sorted(int *arr, int n){
if (n==1){
return true;
}
bool restarr=sorted(arr+1, n-1);
if (arr[0]<arr[1] && restarr){
return true;
}
return false;
}
int xch(int*arr, int a,int b){
int temp;
temp=arr[a];
arr[a]=arr[b];
arr[b]=temp;
}
int main() {
int arr[]={1,2,6,4,5};
cout<<sorted(arr,5);
return 0;
}
Comments
Post a Comment