Answer:
The following are the program in the Java Programming Language.
//define boolean type function with argument list
bool isSorted(int a[], int n, bool status)
{
//declare boolean type variable and initialize it to true
bool flag = true;
//check that the variable 'status' is equal to true
if(status == true)
{//set the for loop that iterates from 1 to n-1
for (int i=0; i<n-1; i++)
//check the array elements is greater than its elements by adding 1
if (a[i] > a[i+1])
//then, initialize flag to false
flag = false;
}
}
Explanation:
- Firstly, define the boolean data type function 'isSorted()' and pass arguments in its parentheses, which are integer data type array argument 'a', integer data type variable 'n' and boolean data type variable 'status'.
- Then, declare the boolean data type variable 'flag' and initialize it to 'true'.
- Set the if conditional statement to check that the variable 'status' is equal to true.
- Then, set the for loop that iterates from 1 to the variable 'n' by subtracting 1
- and check the elements of the array is greater than its elements by adding 1 then, initialize flag from true to false.