Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Insertion Sort
#include <iostream> #include <climits> using namespace std; /* * Function to perform Insertion Sort * Parameters: (Array, Array size) */ void insertionSort(int a[], int n) { int key; for(int i = 1; i < n; ++i) { key = a[i]; int j = i-1; while(j >= 0 && a[j] > key) { a[j+1] = a[j]; --j; } a[j+1] = key; } } /* * Function to print elements of an array * Parameters: (Array, Array size) */ void printArray(int arr[], int n) { int i; for (i = 0; i < n; i++) cout << arr[i] << " "; cout << endl << endl; } int main() { int n = 10; int a[n] = {5, 0, INT_MAX, 11, 11, 1, -2, -11, 24, INT_MIN}; cout << "Unsorted Array: " << endl; printArray(a, n); insertionSort(a, n); cout << "Sorted Array: " << endl; printArray(a, n); return 0; }
run
|
edit
|
history
|
help
0
Codigo Luz Led
stream1
Expected types
Float
Geometric Series
without HLD range Quey can be handled by just using segment tree on the FLATTENED TREE (euler tour)
156
synowie abrahama
AWE
Float