From 5faf66918e7ced26d7e1d916c5f97996f65cd1a8 Mon Sep 17 00:00:00 2001 From: anmolch24 <111361672+anmolch24@users.noreply.github.com> Date: Sat, 1 Oct 2022 21:25:56 +0530 Subject: [PATCH] shell sort in python --- shellSort.oy | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 shellSort.oy diff --git a/shellSort.oy b/shellSort.oy new file mode 100644 index 0000000..3cc37e6 --- /dev/null +++ b/shellSort.oy @@ -0,0 +1,19 @@ +def shell_sort(my_list, list_len): + interval = list_len // 2 + while interval > 0: + for i in range(interval, list_len): + temp = my_list[i] + j = i + while j >= interval and my_list[j - interval] > temp: + my_list[j] = my_list[j - interval] + j -= interval + my_list[j] = temp + interval //= 2 + +my_list = [ 45, 31, 62, 12, 89, 5, 9, 8] +list_len = len(my_list) +print ("The list before sorting is :") +print(my_list) +shell_sort(my_list, list_len) +print ("\nThe list after performing shell sorting is :") +print(my_list)