insertionsort

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include<time.h> using namespace std; //insetion sort - best case O(n) and worst case is O(n^2) int main() { int a[] = {39,54,10,28,95,7,1}; int i = 1;int j; clock_t start = clock(); while(i<7){ j = i-1; int temp = a[i]; while(a[j]>temp && j>=0) { a[j+1] = a[j]; j=j-1; } a[j+1] = temp; i++; } clock_t end = clock(); cout<<"time = "<<end-start<<"\n"; for(int i=0;i<7;i++) cout<<a[i]<<"\t"; return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines