Write a method called switchPairs that switches the order of values in the list in a pairwise

Question:

Write a method called switchPairs that switches the order of values in the list in a pairwise fashion. Your method should switch the order of the first two values, then switch the order of the next two, switch the order of the next two, and so on. If the list contains an odd number of values, the final element is not moved. For example, if the list initially stores [10, 25, 31, 47, 52, 68, 77], your method should switch the first pair ( 10 and 25 ), the second pair ( 31 and 47 ), and the third pair ( 5 2 and 68 ) to yield [25, 10, 47, 31, 68, 52, 77].

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

Step by Step Answer:

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