id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-arrays > apcsaArraysSingleBubbleSortPass
prev  |  next  |  chance

Heads up, this is a harder problem. Congratulations on making it here!


Given an input array of ints, swap each of the consecutive elements of the array with the elements one index higher, but only when the earlier value is greater than the later value.  Thus, the element at index 0 is (potentially) swapped with the element at index 1, the element with index 1 is (potentially) swapped with the element at index 2, and so on.  Return the modified array, or a copy of it with the described modifications.
HINT
Note that this is not a complete sort, it only makes a single pass through the array. The result of this should be that the highest element "moves" to the end of the array.

apcsaArraysSingleBubbleSortPass([3, 4]) → [3, 4]
apcsaArraysSingleBubbleSortPass([8, 5, 3, 4, 5]) → [5, 3, 4, 5, 8]
apcsaArraysSingleBubbleSortPass([9, 2, 4, 6]) → [2, 4, 6, 9]

...Save, Compile, Run (ctrl-enter)

public int[] apcsaArraysSingleBubbleSortPass(int[] nums) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 260

Copyright Nick Parlante 2017 - privacy