From 95548caf8bc8cd74f74a6b313891b3eacc6365cc Mon Sep 17 00:00:00 2001 From: ayush246 <37112252+ayush246@users.noreply.github.com> Date: Sat, 19 Oct 2019 10:16:51 +0530 Subject: [PATCH 1/5] Added with required updates --- sorts/double_sort.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 sorts/double_sort.py diff --git a/sorts/double_sort.py b/sorts/double_sort.py new file mode 100644 index 000000000000..ffff8654c1f4 --- /dev/null +++ b/sorts/double_sort.py @@ -0,0 +1,15 @@ +print("enter the list to be sorted") +lst = [int(x) for x in input().split()] # inputing elements of the list in one line +no_of_elements=len(lst) +for i in range(0,int(((no_of_elements-1)/2)+1)): # we dont need to traverse to end of list as + for j in range(0,no_of_elements-1): + if (lst[j+1] Date: Sat, 19 Oct 2019 12:16:33 +0530 Subject: [PATCH 2/5] Updated --- sorts/double_sort.py | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/sorts/double_sort.py b/sorts/double_sort.py index ffff8654c1f4..912ead256a65 100644 --- a/sorts/double_sort.py +++ b/sorts/double_sort.py @@ -1,15 +1,33 @@ +def double_sort(lst): + """this sorting algorithm sorts an array using the principle of bubble sort , + but does it both from left to right and right to left , + hence i decided to call it "double sort" + :param collection: mutable ordered sequence of elements + :return: the same collection in ascending order + Examples: + >>> double_sort([-1 ,-2 ,-3 ,-4 ,-5 ,-6 ,-7]) + [-7, -6, -5, -4, -3, -2, -1] + >>> double_sort([]) + [] + >>> double_sort([-1 ,-2 ,-3 ,-4 ,-5 ,-6]) + [-6, -5, -4, -3, -2, -1] + >>> double_sort([-3, 10, 16, -42, 29]) == sorted([-3, 10, 16, -42, 29]) + True + """ + no_of_elements=len(lst) + for i in range(0,int(((no_of_elements-1)/2)+1)): # we dont need to traverse to end of list as + for j in range(0,no_of_elements-1): + if (lst[j+1] Date: Sat, 19 Oct 2019 14:25:31 +0530 Subject: [PATCH 3/5] required updates --- sorts/double_sort.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sorts/double_sort.py b/sorts/double_sort.py index 912ead256a65..9ec664690dfc 100644 --- a/sorts/double_sort.py +++ b/sorts/double_sort.py @@ -26,8 +26,9 @@ def double_sort(lst): lst[no_of_elements-1-j]=lst[no_of_elements-2-j] lst[no_of_elements-2-j]=temp return lst -print("enter the list to be sorted") -lst = [int(x) for x in input().split()] # inputing elements of the list in one line +if __name__ == "__main__": + print("enter the list to be sorted") + lst = [int(x) for x in input().split()] # inputing elements of the list in one line sorted_lst=double_sort(lst) print("the sorted list is") print(sorted_lst) From 8f129adb70aeb94047d340c413e918ffcca0f0db Mon Sep 17 00:00:00 2001 From: ayush246 <37112252+ayush246@users.noreply.github.com> Date: Sat, 19 Oct 2019 14:27:00 +0530 Subject: [PATCH 4/5] Update double_sort.py --- sorts/double_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/double_sort.py b/sorts/double_sort.py index 9ec664690dfc..dd28f4df27c0 100644 --- a/sorts/double_sort.py +++ b/sorts/double_sort.py @@ -29,6 +29,6 @@ def double_sort(lst): if __name__ == "__main__": print("enter the list to be sorted") lst = [int(x) for x in input().split()] # inputing elements of the list in one line -sorted_lst=double_sort(lst) + sorted_lst=double_sort(lst) print("the sorted list is") print(sorted_lst) From 3dabed1213987bf2315d0acd627c3b72868c2086 Mon Sep 17 00:00:00 2001 From: ayush246 <37112252+ayush246@users.noreply.github.com> Date: Sat, 19 Oct 2019 16:02:27 +0530 Subject: [PATCH 5/5] Update double_sort.py --- sorts/double_sort.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sorts/double_sort.py b/sorts/double_sort.py index dd28f4df27c0..011e17d8f035 100644 --- a/sorts/double_sort.py +++ b/sorts/double_sort.py @@ -30,5 +30,5 @@ def double_sort(lst): print("enter the list to be sorted") lst = [int(x) for x in input().split()] # inputing elements of the list in one line sorted_lst=double_sort(lst) -print("the sorted list is") -print(sorted_lst) + print("the sorted list is") + print(sorted_lst)