Created
September 11, 2018 19:15
-
-
Save completejavascript/95d916784fb804bf5af3e21a827f2f3b to your computer and use it in GitHub Desktop.
This file contains 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
void InsertionSort(int *a, int N) | |
{ | |
int pos, x; | |
for(int i = 1; i < N; i++) | |
{ | |
pos = i - 1; | |
x = a[i]; | |
// giả sử dãy a[0], a[1], ... , a[i] đã sắp xếp | |
// bắt đầu từ a[i], duyệt về đầu mảng và tìm vị trí thích hợp cho a[i] | |
while(pos >= 0 && a[pos] > x) | |
{ | |
a[pos + 1] = a[pos]; | |
pos--; | |
} | |
a[pos+1] = x; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment