From a81e672f1fd481dfdce955aa818a589985dfc73e Mon Sep 17 00:00:00 2001 From: kaustuvkaran01 Date: Wed, 23 Oct 2019 22:43:53 +0530 Subject: [PATCH] Added code for bubble and insertion sort --- bubblesort.hpp | 15 +++++++++++++++ insertion_sort.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 bubblesort.hpp create mode 100644 insertion_sort.cpp diff --git a/bubblesort.hpp b/bubblesort.hpp new file mode 100644 index 0000000..36a1a04 --- /dev/null +++ b/bubblesort.hpp @@ -0,0 +1,15 @@ +template +void bubblesort(T a[], int size) { + for (int i = o; i < size; i++) + { + for (size_t j = 0; j < i-1; j++) + { + if (a[j] > a[j+1]) + { + T t = a[j]; + a[j] = a[j+1]; + a[j+1]=t; + } + } + } +} diff --git a/insertion_sort.cpp b/insertion_sort.cpp new file mode 100644 index 0000000..7378703 --- /dev/null +++ b/insertion_sort.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; +void inssort(int arr1[], int size){ + int temp,i; + for(int i=1;i=0)){ + arr1[j+1]=arr1[j]; + j--; + } + arr1[j+1]=temp; + } +} +void main(){ + const int size=5; + int arr1[size]; + clrscr(); + for(int i=0;i>arr1[i]; + } + inssort(arr1,size); + for(int i=0;i