Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Last active September 11, 2018 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save completejavascript/3ec23a5aaea325035f46051a6cc66721 to your computer and use it in GitHub Desktop.
Save completejavascript/3ec23a5aaea325035f46051a6cc66721 to your computer and use it in GitHub Desktop.
void SelectionSort(int *a, int N)
{
for(int i = 0; i < N - 1; i++)
{
int idmin = i;
// Tìm ra phần tử có giá trị nhỏ nhất
for(int j = i + 1; j < N; j++)
if(a[j] < a[idmin])
idmin = j;
// Đổi chỗ phần tử đầu tiên của dãy còn lại với phần tử nhỏ nhất
swap(a[i], a[idmin]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment