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

 

tmhscs@gmail.com sort > sort_insertionSortOnePass
prev  |  next  |  chance

Given an integer array and a specific index, perform the Insertion Sort algorithm on the value at the specified index. Assume that the first index-1 spots in the array are already sorted least to greatest. Your goal is to swap the value at the specified index repeatedly to the left as long as the specified element is smaller than the element on its left.


sort_insertionSortOnePass([2, 3, 4, 5, 1], 4) → [1, 2, 3, 4, 5]
sort_insertionSortOnePass([1, 3, 4, 2, 5], 3) → [1, 2, 3, 4, 5]
sort_insertionSortOnePass([1, 3, 2, 4, 5], 2) → [1, 2, 3, 4, 5]

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

public int[] sort_insertionSortOnePass(int[] nums, int index){ }

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

Post-solution available

Copyright Nick Parlante 2017 - privacy