Created
July 12, 2017 15:01
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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