#include <iostream>
#include <vector>

bool issort(std::vector<int>& arr, int n) {
    // base case
    if (n == 0 || n == 1) {
        std::cout << "No elements or single element array" << std::endl;
        return true;
    }

    // recursive case
    if (arr[n-1] > arr[n]) {
        std::cout << "Array is not sorted" << std::endl;
        return false;
    }

    return issort(arr, n-1);
}

int main() {
    std::vector<int> arr = {1, 2, 3, 4, 5};
    int n = arr.size();

    if (issort(arr, n-1)) {
        std::cout << "Array is sorted" << std::endl;
    } else {
        std::cout << "Array is not sorted" << std::endl;
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: