From e3acc25acf41cfbb443c215f3e12a1339be56438 Mon Sep 17 00:00:00 2001 From: Oikite <88682918+Oiklite01@users.noreply.github.com> Date: Fri, 1 Oct 2021 23:05:01 +0530 Subject: [PATCH] Added a Bubble and insertion sort code Takes space separated integers as inputs and sorts them with bubble sort and insertion sort and compares the time it took by both of them --- Sort comparison | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Sort comparison diff --git a/Sort comparison b/Sort comparison new file mode 100644 index 0000000..fd6e4b6 --- /dev/null +++ b/Sort comparison @@ -0,0 +1,38 @@ +#Bubble Sort +def bubble_sort(a): + for x in range(0,len(a)-1): + for y in range(0,len(a)-1-x): + if a[y]>a[y+1]: + a[y],a[y+1]=a[y+1],a[y] + return a +def insertion_sort(a): + for x in range(1,len(a)): + tmp=a[x] + for y in range(x-1,-2,-1): + if tmp