1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mashutka [201]
3 years ago
11

Write the definition of a function named isSorted that receives three arguments: an array of int , an int that indicates the num

ber 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 the array is sorted in ascending order. If the bool argument is false then the function returns true if and only if the array is sorted in descending order. In all other cases the function returns false.You may assume that the array has at least two elements.
Computers and Technology
1 answer:
vazorg [7]3 years ago
4 0

Answer:

The method definition to this question can be given as:

Method Definition:

bool isSorted(int a[], int n, bool status)  //function definition

{

//function body

bool flag = true;          //define Bool(Boolean) variable.

if(status == true)  //check condition.

{

for (int i=0; i<n-1; i++)         //loop for search

{

if (a[i] > a[i+1])         //check array elements

{

flag = false;         //change bool variable value.

}

}

}

else       //else block

{

for (int i=n-1; i > 0; i--)  //loop

{

if (a[i] > a[i-1])   //if block

{

flag = false;     //change bool variable value.

}

}

}

return flag;      //return value.

}  

Explanation:

In the above method definition firstly we define the method that is isSorted(). This method returns true or false value because its return type is bool. In the method, we define the bool variable that is flag. Then we use the condition by using conditional statements. in the if block we check that if status equal to true then we use the for loop in the for loop we define variable i that is used for search array elements it will go to n-1 that is the total number of an array is decrement by 1. In this loop, we use the if condition that is if elements of a[i] is greater then a[i+1] flag will return false. In the else block we use the for loop for search array elements in this loop we use the if block that checks that elements of a[i] is greater then a[i-1]. if it is true it returns false. end of loop end of else block the function will return value.

You might be interested in
Not everything is a success all of the time! So do you know which version of Windows was the least popular?
mario62 [17]

Answer:

windows xp

Explanation:

I think because it is not fast and don't play the games and programs which have higher requirements

7 0
3 years ago
With a word processor, you can create all of the following EXCEPT __________.
Nata [24]
You cannot create a database wurg a word processor
8 0
3 years ago
How barcodes can be used in a library. Consider the type of files needed and how the system can track where books are in the lib
Likurg_2 [28]

Answer:

MORE INFO PLZ

Explanation:

6 0
3 years ago
How to find the average range of cells A1:A10
Ad libitum [116K]
Go to a blank cell and type

         =AVERAGE(A1:A10)      then  <ENTER>

As if by magic, the average of those cells
will appear where you typed the formula.
5 0
3 years ago
What are different social phenomenas are you aware of that used part of a social movement, change, or cause
marin [14]

Answer:

Social change in the broadest sense is any change in social relations. Viewed this way, social change is an ever-present phenomenon in any society.

Explanation:

7 0
2 years ago
Other questions:
  • Create a trigger that prevents anychange(insert, update, or delete)to the grade attribute of the takesrelation that would change
    14·1 answer
  • Suppose a reference variable of type Double called myDouble has already been declared. There is also a double variable x that ha
    13·1 answer
  • A computer with 5 stage pipeline like the one descrive in class delas with conditional branches by stalling for the next three c
    5·1 answer
  • Join my among us code<br> SHUHZF
    6·2 answers
  • Emails, Documents, Videos and Audios are examples of- (a) Structured data (b) Unstructured data (c) Semi-structured data (d) Non
    10·1 answer
  • Yazmin is reading a book that has 74 pages. She has read 38 pages. How many more pages does she need to read to finish the book​
    6·1 answer
  • An intruder with malicious intent breaks into an office and steals a hard drive containing sensitive information about the compa
    5·1 answer
  • 1. Readability, navigation, consistency, layout and typography are all factors which
    11·1 answer
  • What are the differences between switches and routers? cse question
    8·1 answer
  • *the sticker, available in the middle section of the prescription label, will indicate if the customer requested non-safety caps
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!