C++
int array_size = n \\ n is the conceptual limit of the array
double array[array_size];
void IsSorted(array[])
{
int sort_check = 0;
int count_n = 0;
while(sort_check ==0 || count_n == array_size)
{
if(array[count_n] > array[count_n + 1])
sort_check++;
count_n++;
}
if(sort_check != 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
The algorithm will work for any value of n, as it will loop through the whole array or when it finds an unsorted pairing. The algorithm will work for any set of numbers within the array and any permutation of the set as the array is to hold double values. The solution finishes either when it discovers an unsorted pair or when it goes through the entire array, both being finite amounts of time.
Bam.
No comments:
Post a Comment