usingnamespacestd; ///排序后输出函数 boolOutput(intb[],intlength) { for(inti=0;i<length;i++) { cout<<b[i]<<""; } cout<<endl; returntrue; } ///插入排序 voidInsertionSort(intarr[],intsize_arr) { for(inti=1;i<size_
// main.cpp // greedy #include <iostream> using std::cout; using std::cin; using std::string; #define SIZEOF_ARRAY(a) (sizeof(a)/sizeof(a[0])) template<typename T> void insertion_sort(T *a, size_t n) { T tmp; size_t j, p; for (p = 1; p < n; p++) { tmp = ...
实现代码(InsertSort.cpp) #include <iostream> using namespace std; /* * 直接插入排序 * 参数说明: * a -- 待排序的数组 * n -- 数组的长度 */ void insertSort(int* a, int n) { int i, j, k; for (i = 1; i < n; i++) { //为a[i]在前面的a[0...i-1]有序区间中找一个...
swap(&a[i], &a[right-1]); /* restore pivot */ quicksort(a, left, i-1); quicksort(a, i+1, right); } else { insertion_sort(a+left, right-left+1); } } template<typename T> void sort(T *a, size_t n) { quicksort(a, 0, n-1); } template<typename T> void print_ar...
Breadcrumbs Solving-DSA-Problems / insertionSort.cpp Latest commit Cannot retrieve latest commit at this time. HistoryHistory File metadata and controls Code Blame 46 lines (36 loc) · 679 Bytes Raw #include <iostream> using namespace std; void printarray(int a[], int n) { for (int i...
36 changes: 36 additions & 0 deletions 36 insertionSort.cpp Original file line numberDiff line numberDiff line change @@ -0,0 +1,36 @@ #include <iostream> using namespace std;void insertionSort(int arr[], int n){ for(int i=1; i<n;i++){...
AList::InsertionSort() { //Pre: the N.O. Alist is valid //Post: the N.O. Alist is unchanged, except that //its elements are now in ascending order int j; bool done; for (int i = 1; i<size; i++) { j=i; done=false...
*/// Virtual_Judge —— Insertion Sort Aizu - ALDS1_1_A.cpp created by VB_KoKing on 2019,04,28,08./* Procedural objectives: Procedural thinking: Functions required by the program: Variables required by the program: *//* My dear Max said: ...
Edit & run on cpp.sh 1 2 3 4 5 6 7 8 9 10 11 12 13 14 voidinsertion_sort (intarr[],intlength){intj, temp;for(inti = 0; i < length; i++){ j = i;while(j > 0 && arr[j] < arr[j-1]){ temp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = temp; j--; } ...
// Virtual_Judge —— Insertion Sort Aizu - ALDS1_1_A.cpp created by VB_KoKing on 2019,04,28,08. /* Procedural objectives: Procedural thinking: Functions required by the program: Variables required by the program: */ /* My dear Max said: ...