Skip to content

Instantly share code, notes, and snippets.

@JiaruiTracy
Created July 12, 2017 15:01
Show Gist options
  • Save JiaruiTracy/83aca67bf63389553d615c636115fdd4 to your computer and use it in GitHub Desktop.
Save JiaruiTracy/83aca67bf63389553d615c636115fdd4 to your computer and use it in GitHub Desktop.
Using insertion sorting to insert some elements, every time inserts one value to the sorted array.
public void insert(int rand){
int cur = rand;
int j = num-1;
while(j>=0&&randNum[j]>cur){
randNum[j+1]=randNum[j--];
}
randNum[j+1]=cur;
num++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment