Write a method called isPairwiseSorted that returns whether or not a list of integers is pairwise sorted.

Question:

Write a method called isPairwiseSorted that returns whether or not a list of integers is pairwise sorted. A list is considered pairwise sorted if each successive pair of numbers is in nondecreasing order. For example, if a variable called list stores [3, 8, 2, 5, 19, 24, –3, 0, 4, 4, 8, 205, 42] , then the call of list.isPairwiseSorted() should return true because the successive pairs of this list are all sorted: (3, 8), (2, 5), (19, 24), (–3, 0), (4, 4), (8, 205). The extra value 42 at the end had no effect on the result because it is not part of a pair. If the list had instead stored [7, 42, 308, 409, 19, 17, 2] , then the method should return false because the pair (19, 17) is not in sorted order. If a list is so short that it has no pairs, then it is considered to be pairwise sorted.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: