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.
Step by Step Answer:
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp