98.1k views
2 votes
Write the definition of a function named isSorted that receives three arguments: an array of int, an int that indicates the number of elements of interest in the array, and a bool. If the bool argument is true then the function returns true if and only if

User Ethem
by
5.0k points

1 Answer

6 votes

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.
User Helping Hands
by
5.4k points