InSertionSort in array

// xắp xếp chèn /* */ #include<iostream> using namespace std; // xắp xếp chèn void InSertionSort(int a[],int n) { for (int i = 1; i < n; i++) { int x = a[i]; int j; for (j = i - 1; j >= 0; j--) { if (a[j] > x) { a[j + 1] = a[j]; } else { break; } } a[j + 1] = x; } } int main() { int a[] = { 3,1,5 }; int n = sizeof(a) / sizeof(a[0]); InSertionSort(a, n); for (int i = 0; i < n; i++) { cout << a[i]; } system("pause"); return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.