diff --git a/sorting-algo/insertion_sorting.cpp b/sorting-algo/insertion_sorting.cpp new file mode 100644 index 0000000..450c0bd --- /dev/null +++ b/sorting-algo/insertion_sorting.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; + +void insertion(int[],int); +void showData(int[],int); + +main(){ + int size = 40,counter = 0; + int array[size]; //Size can be changed, just to prove it works + cout << "************FILLING ARRAY************" << endl; + for(int i=size;i>0;i--){ //Worst case, as it is ordered backwards + array[counter]= i; + cout << "Array, position " << counter << ": " << array[counter] << endl; + counter++; + } + cout << "************FINISHED FILLING, STARTING SORTING************" << endl; + insertion(array,size); +} + +void insertion(int data[], int size){ + int aux=0,j=0; + for(int i=1;i<=size;i++){ + j=i; + aux=data[i]; + while(j>0 && aux