Below is an array declaration and an integer counter that specifies how many dat
ID: 3585320 • Letter: B
Question
Below is an array declaration and an integer counter that specifies how many data values are in the array (i.e., it may not be full) Using that array and counter, write two different methods. The array has been instantiated and data placed in it before the methods are called; the dataSize variable has also been set up. private intl ] data; private in dataSize; A method that checks whether the array is in non-descending order (ascending order plus duplicates are allowed even though they are not ascending). The method returns a boolean for whether the array is sorted or not. Sample sorted data: 1. 1 4 4 6 23Explanation / Answer
Solution:
public boolean orderNonDecending(int *data, int dataSize) // Function body
{
for(int i=0; i<dataSize; i++)
{
for(int j=0; j<dataSie; j++)
{
if(data[i]> data[j]) // Checking if there is any descending order available in the array
return false; // if so return false
}
}
return true; // else return ture.
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.