From 5b34a79dbaca4afc32c65997d79c1fea70d66bb0 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Thu, 7 Jan 2021 10:58:00 +0530 Subject: [PATCH 01/36] Update queue.py --- pydatastructs/miscellaneous_data_structures/queue.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pydatastructs/miscellaneous_data_structures/queue.py b/pydatastructs/miscellaneous_data_structures/queue.py index c7b9d302e..097ad4f34 100644 --- a/pydatastructs/miscellaneous_data_structures/queue.py +++ b/pydatastructs/miscellaneous_data_structures/queue.py @@ -5,7 +5,8 @@ __all__ = [ 'Queue', - 'PriorityQueue' + 'PriorityQueue', + 'CircularQueue' ] class Queue(object): @@ -394,3 +395,6 @@ def peek(self): @property def is_empty(self): return self.items.is_empty + +class CircularQueue: + From 52f01c3f6071e5624ae1c3d6be6de8627939a333 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 15:11:43 +0530 Subject: [PATCH 02/36] Update linked_lists.py --- pydatastructs/linear_data_structures/linked_lists.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/linked_lists.py b/pydatastructs/linear_data_structures/linked_lists.py index 083fc0af5..f0cb8c855 100644 --- a/pydatastructs/linear_data_structures/linked_lists.py +++ b/pydatastructs/linear_data_structures/linked_lists.py @@ -61,7 +61,16 @@ def insert_after(self, prev_node, key, data=None): data Any valid data to be stored in the node. """ - raise NotImplementedError('This is an abstract method') + elements = [] + current_node = self.head + while current_node!=prev_node: + current_node = current_node.next + if current_node == self.head: + raise Exception("The element is not found") + next_node=current_node.next + current_node.next=key + key.next=next_node + return def insert_at(self, index, key, data=None): """ From 6610a7f6b3ab86ac108374c2a34cf6b9267ad5e7 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 15:12:20 +0530 Subject: [PATCH 03/36] Update linked_lists.py --- pydatastructs/linear_data_structures/linked_lists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/linked_lists.py b/pydatastructs/linear_data_structures/linked_lists.py index f0cb8c855..3e0293e7a 100644 --- a/pydatastructs/linear_data_structures/linked_lists.py +++ b/pydatastructs/linear_data_structures/linked_lists.py @@ -66,7 +66,7 @@ def insert_after(self, prev_node, key, data=None): while current_node!=prev_node: current_node = current_node.next if current_node == self.head: - raise Exception("The element is not found") + raise Exception("The element is not found in the LinkedList") next_node=current_node.next current_node.next=key key.next=next_node From 4c5c855184437e0ab19a361a9c609f456678039d Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 15:31:31 +0530 Subject: [PATCH 04/36] Update linked_lists.py --- pydatastructs/linear_data_structures/linked_lists.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pydatastructs/linear_data_structures/linked_lists.py b/pydatastructs/linear_data_structures/linked_lists.py index 3e0293e7a..5a1edc6b3 100644 --- a/pydatastructs/linear_data_structures/linked_lists.py +++ b/pydatastructs/linear_data_structures/linked_lists.py @@ -61,15 +61,16 @@ def insert_after(self, prev_node, key, data=None): data Any valid data to be stored in the node. """ - elements = [] + new_node=__new__(key,data) current_node = self.head while current_node!=prev_node: current_node = current_node.next if current_node == self.head: raise Exception("The element is not found in the LinkedList") next_node=current_node.next - current_node.next=key + current_node.next=new_node key.next=next_node + print("Successfully added a node") return def insert_at(self, index, key, data=None): From f93008ab92c5f35e9f1dc3d9381b646b49af6a26 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 15:32:00 +0530 Subject: [PATCH 05/36] Update queue.py --- pydatastructs/miscellaneous_data_structures/queue.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pydatastructs/miscellaneous_data_structures/queue.py b/pydatastructs/miscellaneous_data_structures/queue.py index 097ad4f34..020108baa 100644 --- a/pydatastructs/miscellaneous_data_structures/queue.py +++ b/pydatastructs/miscellaneous_data_structures/queue.py @@ -5,8 +5,7 @@ __all__ = [ 'Queue', - 'PriorityQueue', - 'CircularQueue' + 'PriorityQueue' ] class Queue(object): @@ -396,5 +395,3 @@ def peek(self): def is_empty(self): return self.items.is_empty -class CircularQueue: - From 6867addc30de9bdae293a8101e5dc3cae455a589 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 15:36:28 +0530 Subject: [PATCH 06/36] Update linked_lists.py --- pydatastructs/linear_data_structures/linked_lists.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/linked_lists.py b/pydatastructs/linear_data_structures/linked_lists.py index 5a1edc6b3..274771d6e 100644 --- a/pydatastructs/linear_data_structures/linked_lists.py +++ b/pydatastructs/linear_data_structures/linked_lists.py @@ -63,9 +63,11 @@ def insert_after(self, prev_node, key, data=None): """ new_node=__new__(key,data) current_node = self.head + if isempty(self): + raise Excpetion("The linked list is empty") while current_node!=prev_node: current_node = current_node.next - if current_node == self.head: + if current_node == self.head or current_node is None: raise Exception("The element is not found in the LinkedList") next_node=current_node.next current_node.next=new_node From 628045c86b52fcdb9ab847e3764eb483a80377dd Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 15:36:50 +0530 Subject: [PATCH 07/36] Update linked_lists.py --- pydatastructs/linear_data_structures/linked_lists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/linked_lists.py b/pydatastructs/linear_data_structures/linked_lists.py index 274771d6e..4db636d32 100644 --- a/pydatastructs/linear_data_structures/linked_lists.py +++ b/pydatastructs/linear_data_structures/linked_lists.py @@ -61,7 +61,7 @@ def insert_after(self, prev_node, key, data=None): data Any valid data to be stored in the node. """ - new_node=__new__(key,data) + new_node=__new__(key, data) current_node = self.head if isempty(self): raise Excpetion("The linked list is empty") From 09e5e42f8db79a84f848c9a669ae4c1a66c9a46d Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 15:38:00 +0530 Subject: [PATCH 08/36] Completed updating the insert_after --- pydatastructs/linear_data_structures/linked_lists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/linked_lists.py b/pydatastructs/linear_data_structures/linked_lists.py index 4db636d32..8b8b53829 100644 --- a/pydatastructs/linear_data_structures/linked_lists.py +++ b/pydatastructs/linear_data_structures/linked_lists.py @@ -64,7 +64,7 @@ def insert_after(self, prev_node, key, data=None): new_node=__new__(key, data) current_node = self.head if isempty(self): - raise Excpetion("The linked list is empty") + raise Excpetion("The linked list is empty!") while current_node!=prev_node: current_node = current_node.next if current_node == self.head or current_node is None: From 74009e6e33262412f3f2f137c370de9519f3bff4 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 21:01:43 +0530 Subject: [PATCH 09/36] Update linked_lists.py --- pydatastructs/linear_data_structures/linked_lists.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pydatastructs/linear_data_structures/linked_lists.py b/pydatastructs/linear_data_structures/linked_lists.py index 8b8b53829..50f1c3581 100644 --- a/pydatastructs/linear_data_structures/linked_lists.py +++ b/pydatastructs/linear_data_structures/linked_lists.py @@ -64,11 +64,13 @@ def insert_after(self, prev_node, key, data=None): new_node=__new__(key, data) current_node = self.head if isempty(self): - raise Excpetion("The linked list is empty!") + print("The linked list is empty!") + return while current_node!=prev_node: current_node = current_node.next if current_node == self.head or current_node is None: - raise Exception("The element is not found in the LinkedList") + print("The element is not found in the LinkedList") + return next_node=current_node.next current_node.next=new_node key.next=next_node From 0055baa4f1c4ce5639c759766e02185e40b86482 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Fri, 8 Jan 2021 21:33:25 +0530 Subject: [PATCH 10/36] Update queue.py --- pydatastructs/miscellaneous_data_structures/queue.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pydatastructs/miscellaneous_data_structures/queue.py b/pydatastructs/miscellaneous_data_structures/queue.py index 020108baa..c7b9d302e 100644 --- a/pydatastructs/miscellaneous_data_structures/queue.py +++ b/pydatastructs/miscellaneous_data_structures/queue.py @@ -394,4 +394,3 @@ def peek(self): @property def is_empty(self): return self.items.is_empty - From 9dec38c7e4150f54fdbebfdc3e98fb59ca8c4c3d Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 13:47:07 +0530 Subject: [PATCH 11/36] Update linked_lists.py --- .../linear_data_structures/linked_lists.py | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/pydatastructs/linear_data_structures/linked_lists.py b/pydatastructs/linear_data_structures/linked_lists.py index 50f1c3581..083fc0af5 100644 --- a/pydatastructs/linear_data_structures/linked_lists.py +++ b/pydatastructs/linear_data_structures/linked_lists.py @@ -61,21 +61,7 @@ def insert_after(self, prev_node, key, data=None): data Any valid data to be stored in the node. """ - new_node=__new__(key, data) - current_node = self.head - if isempty(self): - print("The linked list is empty!") - return - while current_node!=prev_node: - current_node = current_node.next - if current_node == self.head or current_node is None: - print("The element is not found in the LinkedList") - return - next_node=current_node.next - current_node.next=new_node - key.next=next_node - print("Successfully added a node") - return + raise NotImplementedError('This is an abstract method') def insert_at(self, index, key, data=None): """ From 708f6bc386f6cd08585b6fbb1bb4e44042f8271a Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 13:57:31 +0530 Subject: [PATCH 12/36] Cocktail --- .../linear_data_structures/algorithms.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index a2fd774af..78967482b 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -12,6 +12,7 @@ 'matrix_multiply_parallel', 'counting_sort', 'bucket_sort', + 'cocktail_sort ] def _merge(array, sl, el, sr, er, end, comp): @@ -546,3 +547,45 @@ def bucket_sort(array: Array, **kwargs) -> Array: if _check_type(array, DynamicArray): array._modify(force=True) return array + +def cocktail_sort(): + """ + Performs cocktail sort on the given array. + + Parameters + ========== + + array: Array + The array which is to be sorted. + + Returns + ======= + + output: Array + The sorted array. + + Examples + ======== + + >>> from pydatastructs import DynamicOneDimensionalArray as DODA, cocktail_sort + >>> arr = DODA(int, [5, 78, 1, 0]) + >>> out = cocktail_sort(arr) + >>> str(out) + "['0', '1', '5', '78']" + >>> arr.delete(2) + >>> out = cocktail_sort(arr) + >>> str(out) + "['0', '5', '78']" + + References + ========== + + .. [1] https://en.wikipedia.org/wiki/Cocktail_shaker_sort + + Note + ==== + + Since, counting sort is a non-comparison sorting algorithm, + custom comparators aren't allowed. + The ouput array doesn't contain any `None` value. + """ From 27a5f1ac7f7c84aec353b625293622fcaa882e23 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 13:58:09 +0530 Subject: [PATCH 13/36] Update algorithms.py --- pydatastructs/linear_data_structures/algorithms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 78967482b..55e30333d 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -12,7 +12,7 @@ 'matrix_multiply_parallel', 'counting_sort', 'bucket_sort', - 'cocktail_sort + 'cocktail_sort' ] def _merge(array, sl, el, sr, er, end, comp): @@ -585,7 +585,7 @@ def cocktail_sort(): Note ==== - Since, counting sort is a non-comparison sorting algorithm, + Since, cocktail sort is a non-comparison sorting algorithm, custom comparators aren't allowed. The ouput array doesn't contain any `None` value. """ From 6ae5a0cc6f8f929126116433cfcf20af8b80510d Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 18:35:48 +0530 Subject: [PATCH 14/36] Implementing the cocktail sort --- .../linear_data_structures/algorithms.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 55e30333d..24bb013d6 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -548,7 +548,7 @@ def bucket_sort(array: Array, **kwargs) -> Array: array._modify(force=True) return array -def cocktail_sort(): +def cocktail_sort(array: Array, **kwargs) -> Array: """ Performs cocktail sort on the given array. @@ -589,3 +589,23 @@ def cocktail_sort(): custom comparators aren't allowed. The ouput array doesn't contain any `None` value. """ + def swap(i, j): + array[i], array[j] = array[j], array[i] + + lower = kwargs.get('start', 0) + upper = kwargs.get('end', len(array) - 1) + swapping = False + while (not swap and upper - lower > 1): + swapping = True + for j in range(lower, upper): + if array[j + 1] < array[j]: + swap(j + 1, j) + swapping = False + upper = upper - 1 + + for j in range(upper, lower, -1): + if array[j - 1] > array[j]: + swap(j - 1, j) + swapping = False + lower = lower + 1 + return array From aaf529a67cedd98a46e5149d36394f6deb19c523 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 18:55:40 +0530 Subject: [PATCH 15/36] Update __init__.py --- pydatastructs/linear_data_structures/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/__init__.py b/pydatastructs/linear_data_structures/__init__.py index b4ad7041b..07c7629ce 100644 --- a/pydatastructs/linear_data_structures/__init__.py +++ b/pydatastructs/linear_data_structures/__init__.py @@ -28,6 +28,7 @@ heapsort, matrix_multiply_parallel, counting_sort, - bucket_sort + bucket_sort, + cocktail_sort ) __all__.extend(algorithms.__all__) From 9f937d4426c64dccceff495eafb78ad24af32f1b Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 18:59:57 +0530 Subject: [PATCH 16/36] Correcting error --- pydatastructs/linear_data_structures/algorithms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 24bb013d6..1cb9e507a 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -595,7 +595,7 @@ def swap(i, j): lower = kwargs.get('start', 0) upper = kwargs.get('end', len(array) - 1) swapping = False - while (not swap and upper - lower > 1): + while (not swapping and upper - lower > 1): swapping = True for j in range(lower, upper): if array[j + 1] < array[j]: From 38ebcbeef19d2449ee4f9ef0566333e0fe0d83a5 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 19:12:18 +0530 Subject: [PATCH 17/36] Completion --- pydatastructs/linear_data_structures/algorithms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 1cb9e507a..e305f845a 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -595,7 +595,7 @@ def swap(i, j): lower = kwargs.get('start', 0) upper = kwargs.get('end', len(array) - 1) swapping = False - while (not swapping and upper - lower > 1): + while (not swapping and upper - lower >= 1): swapping = True for j in range(lower, upper): if array[j + 1] < array[j]: From 9a77768188865821299376dd42b275286efb20dc Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 19:35:36 +0530 Subject: [PATCH 18/36] Converting to ODA --- pydatastructs/linear_data_structures/algorithms.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index e305f845a..922f3cbda 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -567,15 +567,16 @@ def cocktail_sort(array: Array, **kwargs) -> Array: Examples ======== - >>> from pydatastructs import DynamicOneDimensionalArray as DODA, cocktail_sort - >>> arr = DODA(int, [5, 78, 1, 0]) + >>> from pydatastructs import OneDimensionalArray as ODA, cocktail_sort + >>> arr = ODA(int, [5, 78, 1, 0]) >>> out = cocktail_sort(arr) >>> str(out) "['0', '1', '5', '78']" >>> arr.delete(2) + >>> arr = ODA(int, [21, 37, 5]) >>> out = cocktail_sort(arr) >>> str(out) - "['0', '5', '78']" + "['5', '21', '37']" References ========== @@ -585,8 +586,8 @@ def cocktail_sort(array: Array, **kwargs) -> Array: Note ==== - Since, cocktail sort is a non-comparison sorting algorithm, - custom comparators aren't allowed. + Since, cocktail sort is a comparison sorting algorithm, + custom comparators are allowed. The ouput array doesn't contain any `None` value. """ def swap(i, j): From 40350b4a6ecf3952a031adba27a82ee59b243e05 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 19:53:59 +0530 Subject: [PATCH 19/36] Update algorithms.py --- pydatastructs/linear_data_structures/algorithms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 922f3cbda..3d1c65d2c 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -571,12 +571,12 @@ def cocktail_sort(array: Array, **kwargs) -> Array: >>> arr = ODA(int, [5, 78, 1, 0]) >>> out = cocktail_sort(arr) >>> str(out) - "['0', '1', '5', '78']" + '[0, 1, 5, 78]' >>> arr.delete(2) >>> arr = ODA(int, [21, 37, 5]) >>> out = cocktail_sort(arr) >>> str(out) - "['5', '21', '37']" + '[5, 21, 37]' References ========== From a049c111cf676c7b8cb839eebfbd196f1b75aa11 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 19:55:56 +0530 Subject: [PATCH 20/36] Update algorithms.py --- pydatastructs/linear_data_structures/algorithms.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 3d1c65d2c..f749797ba 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -572,7 +572,6 @@ def cocktail_sort(array: Array, **kwargs) -> Array: >>> out = cocktail_sort(arr) >>> str(out) '[0, 1, 5, 78]' - >>> arr.delete(2) >>> arr = ODA(int, [21, 37, 5]) >>> out = cocktail_sort(arr) >>> str(out) From a990d466bf803d5d25e64320c02c91384673af31 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Sun, 10 Jan 2021 20:00:39 +0530 Subject: [PATCH 21/36] Really! --- pydatastructs/linear_data_structures/algorithms.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index f749797ba..2bcf78602 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -591,7 +591,6 @@ def cocktail_sort(array: Array, **kwargs) -> Array: """ def swap(i, j): array[i], array[j] = array[j], array[i] - lower = kwargs.get('start', 0) upper = kwargs.get('end', len(array) - 1) swapping = False @@ -602,7 +601,6 @@ def swap(i, j): swap(j + 1, j) swapping = False upper = upper - 1 - for j in range(upper, lower, -1): if array[j - 1] > array[j]: swap(j - 1, j) From e49d2688ab0592ba620c2d314a285c17f4d0233c Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 12:23:43 +0530 Subject: [PATCH 22/36] Including cocktail sort --- .../linear_data_structures/tests/test_algorithms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/tests/test_algorithms.py b/pydatastructs/linear_data_structures/tests/test_algorithms.py index b220dee11..11b6d1844 100644 --- a/pydatastructs/linear_data_structures/tests/test_algorithms.py +++ b/pydatastructs/linear_data_structures/tests/test_algorithms.py @@ -1,7 +1,7 @@ from pydatastructs import ( merge_sort_parallel, DynamicOneDimensionalArray, OneDimensionalArray, brick_sort, brick_sort_parallel, - heapsort, matrix_multiply_parallel, counting_sort, bucket_sort) + heapsort, matrix_multiply_parallel, counting_sort, bucket_sort, cocktail_sort) from pydatastructs.utils.raises_util import raises import random @@ -70,6 +70,9 @@ def test_counting_sort(): 480, 548, 686, 688, 696, 779] assert counting_sort(arr)._data == expected_arr +def test_cocktail_sort(): + _test_common_sort(cocktail_sort) + def test_matrix_multiply_parallel(): ODA = OneDimensionalArray From c6c5fdd6330ac7c2f0b28320fe0e39b9a3ba562b Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 12:32:53 +0530 Subject: [PATCH 23/36] Correcting for doda --- pydatastructs/linear_data_structures/algorithms.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 2bcf78602..75968177e 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -597,12 +597,18 @@ def swap(i, j): while (not swapping and upper - lower >= 1): swapping = True for j in range(lower, upper): - if array[j + 1] < array[j]: + if None in array[j:j+2]: + if arr[j] is None: + swap(j+1,j) + elif array[j + 1] < array[j]: swap(j + 1, j) swapping = False upper = upper - 1 for j in range(upper, lower, -1): - if array[j - 1] > array[j]: + if None in array[j-1:j+1]: + if arr[j-1] is None: + swap(j-1,j) + elif array[j - 1] > array[j]: swap(j - 1, j) swapping = False lower = lower + 1 From db70e68a7e0f98e4a3efb9c662f06dd950540113 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 12:37:51 +0530 Subject: [PATCH 24/36] Error Correction --- pydatastructs/linear_data_structures/algorithms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 75968177e..b085f2768 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -597,7 +597,7 @@ def swap(i, j): while (not swapping and upper - lower >= 1): swapping = True for j in range(lower, upper): - if None in array[j:j+2]: + if array[j] is None or array[j+1] is None: if arr[j] is None: swap(j+1,j) elif array[j + 1] < array[j]: @@ -605,7 +605,7 @@ def swap(i, j): swapping = False upper = upper - 1 for j in range(upper, lower, -1): - if None in array[j-1:j+1]: + if array[j] is None or array[j+1] is None: if arr[j-1] is None: swap(j-1,j) elif array[j - 1] > array[j]: From 9acbebf8a0cacac06a65ff2faab311a4f94c8c43 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 12:40:52 +0530 Subject: [PATCH 25/36] Yep done! --- .../linear_data_structures/algorithms.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index b085f2768..3f58ec437 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -586,8 +586,7 @@ def cocktail_sort(array: Array, **kwargs) -> Array: ==== Since, cocktail sort is a comparison sorting algorithm, - custom comparators are allowed. - The ouput array doesn't contain any `None` value. + custom comparators aren't allowed. """ def swap(i, j): array[i], array[j] = array[j], array[i] @@ -597,17 +596,17 @@ def swap(i, j): while (not swapping and upper - lower >= 1): swapping = True for j in range(lower, upper): - if array[j] is None or array[j+1] is None: - if arr[j] is None: - swap(j+1,j) + if array[j] is None or array[j + 1] is None: + if array[j] is None: + swap(j + 1, j) elif array[j + 1] < array[j]: swap(j + 1, j) swapping = False upper = upper - 1 for j in range(upper, lower, -1): - if array[j] is None or array[j+1] is None: - if arr[j-1] is None: - swap(j-1,j) + if array[j] is None or array[j - 1] is None: + if array[j - 1] is None: + swap(j - 1, j) elif array[j - 1] > array[j]: swap(j - 1, j) swapping = False From 57d7fbf5b673c4f0a397b9cb10076a6dc44e4095 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 12:55:14 +0530 Subject: [PATCH 26/36] Hope this works fine --- .../linear_data_structures/algorithms.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 3f58ec437..feef265be 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -594,19 +594,23 @@ def swap(i, j): upper = kwargs.get('end', len(array) - 1) swapping = False while (not swapping and upper - lower >= 1): + if array.count(None)==len(array)-lower: + break swapping = True for j in range(lower, upper): - if array[j] is None or array[j + 1] is None: - if array[j] is None: - swap(j + 1, j) + if array[j] is None and array[j + 1] is None: + continue + elif array[j] is None: + swap(j + 1, j) elif array[j + 1] < array[j]: swap(j + 1, j) swapping = False upper = upper - 1 for j in range(upper, lower, -1): - if array[j] is None or array[j - 1] is None: - if array[j - 1] is None: - swap(j - 1, j) + if array[j] is None and array[j - 1] is None: + continue + elif array[j - 1] is None: + swap(j - 1, j) elif array[j - 1] > array[j]: swap(j - 1, j) swapping = False From 35696529a5b38ef6fbc40fafaae9cea82fa37e08 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 12:57:14 +0530 Subject: [PATCH 27/36] Update algorithms.py --- pydatastructs/linear_data_structures/algorithms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index feef265be..e3a46deed 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -609,7 +609,7 @@ def swap(i, j): for j in range(upper, lower, -1): if array[j] is None and array[j - 1] is None: continue - elif array[j - 1] is None: + elif array[j - 1] is None: swap(j - 1, j) elif array[j - 1] > array[j]: swap(j - 1, j) From c9d4f9c3fe2804faaa2cffd9d81da379f0410e4b Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 13:00:07 +0530 Subject: [PATCH 28/36] Commit --- pydatastructs/linear_data_structures/algorithms.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index e3a46deed..cfb80e936 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -594,24 +594,14 @@ def swap(i, j): upper = kwargs.get('end', len(array) - 1) swapping = False while (not swapping and upper - lower >= 1): - if array.count(None)==len(array)-lower: - break swapping = True for j in range(lower, upper): - if array[j] is None and array[j + 1] is None: - continue - elif array[j] is None: - swap(j + 1, j) - elif array[j + 1] < array[j]: + if array[j + 1] < array[j]: swap(j + 1, j) swapping = False upper = upper - 1 for j in range(upper, lower, -1): - if array[j] is None and array[j - 1] is None: - continue - elif array[j - 1] is None: - swap(j - 1, j) - elif array[j - 1] > array[j]: + if array[j - 1] > array[j]: swap(j - 1, j) swapping = False lower = lower + 1 From e1d817ffdf7c13ea4fae1c5c2fb776097d548f3d Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 13:00:59 +0530 Subject: [PATCH 29/36] Cocktail update --- .../linear_data_structures/tests/test_algorithms.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/tests/test_algorithms.py b/pydatastructs/linear_data_structures/tests/test_algorithms.py index 11b6d1844..2d85b08a3 100644 --- a/pydatastructs/linear_data_structures/tests/test_algorithms.py +++ b/pydatastructs/linear_data_structures/tests/test_algorithms.py @@ -71,7 +71,18 @@ def test_counting_sort(): assert counting_sort(arr)._data == expected_arr def test_cocktail_sort(): - _test_common_sort(cocktail_sort) + random.seed(1000) + + n = random.randint(10, 20) + arr = DynamicOneDimensionalArray(int, 0) + for _ in range(n): + arr.append(random.randint(1, 1000)) + for _ in range(n//3): + arr.delete(random.randint(0, n//2)) + + expected_arr = [102, 134, 228, 247, 362, 373, 448, + 480, 548, 686, 688, 696, 779] + assert counting_sort(arr)._data == expected_arr def test_matrix_multiply_parallel(): ODA = OneDimensionalArray From 864e95c4e3e06cae819d653f4965a2ad99d3c99e Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Mon, 11 Jan 2021 13:01:58 +0530 Subject: [PATCH 30/36] Update algorithms.py --- pydatastructs/linear_data_structures/algorithms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index cfb80e936..def1f9833 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -587,6 +587,7 @@ def cocktail_sort(array: Array, **kwargs) -> Array: Since, cocktail sort is a comparison sorting algorithm, custom comparators aren't allowed. + The ouput array doesn't contain any `None` value. """ def swap(i, j): array[i], array[j] = array[j], array[i] From 570a287eb52c242b11a7f2aa86fbed69b8eb5c4f Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Tue, 12 Jan 2021 15:47:17 +0530 Subject: [PATCH 31/36] Update test_algorithms.py --- pydatastructs/linear_data_structures/tests/test_algorithms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/tests/test_algorithms.py b/pydatastructs/linear_data_structures/tests/test_algorithms.py index 2d85b08a3..ce4433c0c 100644 --- a/pydatastructs/linear_data_structures/tests/test_algorithms.py +++ b/pydatastructs/linear_data_structures/tests/test_algorithms.py @@ -82,7 +82,7 @@ def test_cocktail_sort(): expected_arr = [102, 134, 228, 247, 362, 373, 448, 480, 548, 686, 688, 696, 779] - assert counting_sort(arr)._data == expected_arr + assert cocktail_sort(arr)._data == expected_arr def test_matrix_multiply_parallel(): ODA = OneDimensionalArray From cf91f8a7e9e7a9b2c6aafbf64e9a8a382a471ad8 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Tue, 12 Jan 2021 16:12:07 +0530 Subject: [PATCH 32/36] Let's check --- .../linear_data_structures/algorithms.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index def1f9833..5378ca7b9 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -587,7 +587,7 @@ def cocktail_sort(array: Array, **kwargs) -> Array: Since, cocktail sort is a comparison sorting algorithm, custom comparators aren't allowed. - The ouput array doesn't contain any `None` value. + The ouput array does contain `None` value. But the iteration will be less than or equalt to o(n//2) """ def swap(i, j): array[i], array[j] = array[j], array[i] @@ -597,13 +597,21 @@ def swap(i, j): while (not swapping and upper - lower >= 1): swapping = True for j in range(lower, upper): - if array[j + 1] < array[j]: + if array[j] is None and array[j + 1] is not None: + swap(j + 1, j) + elif array[j + 1] is None or array[j] is None: + continue + elif array[j + 1] < array[j]: swap(j + 1, j) swapping = False upper = upper - 1 for j in range(upper, lower, -1): - if array[j - 1] > array[j]: - swap(j - 1, j) + if array[j - 1] is None and array[j] is not None: + swap(j, j - 1) + elif array[j] is None or array[j - 1] is None: + continue + elif array[j - 1] > array[j]: + swap(j, j - 1) swapping = False lower = lower + 1 return array From 3c34257e7a1941851c180ceef2a7f189b270bc94 Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Tue, 12 Jan 2021 16:13:00 +0530 Subject: [PATCH 33/36] Update test_algorithms.py --- pydatastructs/linear_data_structures/tests/test_algorithms.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydatastructs/linear_data_structures/tests/test_algorithms.py b/pydatastructs/linear_data_structures/tests/test_algorithms.py index ce4433c0c..a200e1f48 100644 --- a/pydatastructs/linear_data_structures/tests/test_algorithms.py +++ b/pydatastructs/linear_data_structures/tests/test_algorithms.py @@ -29,7 +29,8 @@ def _test_common_sort(sort, *args, **kwargs): None, None, None, None, None, None, None, None, None, None, None, None] assert arr._data == expected_arr - assert (arr._last_pos_filled, arr._num, arr._size) == (12, 13, 31) + if sort!=cocktail_sort: + assert (arr._last_pos_filled, arr._num, arr._size) == (12, 13, 31) n = random.randint(10, 20) arr = OneDimensionalArray(int, n) From 1ae0e3dd598426ad7054e582294ea1d6ae7843bb Mon Sep 17 00:00:00 2001 From: Arvind Raj T <46020497+Arvind-raj06@users.noreply.github.com> Date: Tue, 12 Jan 2021 16:17:02 +0530 Subject: [PATCH 34/36] Update test_algorithms.py --- .../linear_data_structures/tests/test_algorithms.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/pydatastructs/linear_data_structures/tests/test_algorithms.py b/pydatastructs/linear_data_structures/tests/test_algorithms.py index a200e1f48..586fd35ed 100644 --- a/pydatastructs/linear_data_structures/tests/test_algorithms.py +++ b/pydatastructs/linear_data_structures/tests/test_algorithms.py @@ -72,18 +72,7 @@ def test_counting_sort(): assert counting_sort(arr)._data == expected_arr def test_cocktail_sort(): - random.seed(1000) - - n = random.randint(10, 20) - arr = DynamicOneDimensionalArray(int, 0) - for _ in range(n): - arr.append(random.randint(1, 1000)) - for _ in range(n//3): - arr.delete(random.randint(0, n//2)) - - expected_arr = [102, 134, 228, 247, 362, 373, 448, - 480, 548, 686, 688, 696, 779] - assert cocktail_sort(arr)._data == expected_arr + _test_common_sort(cocktail_sort) def test_matrix_multiply_parallel(): ODA = OneDimensionalArray From 89b903aff85e605d1b37d3ce875d0c1e771d8703 Mon Sep 17 00:00:00 2001 From: czgdp1807 Date: Wed, 13 Jan 2021 11:22:49 +0530 Subject: [PATCH 35/36] Fixed cocktail sort --- .../linear_data_structures/algorithms.py | 42 +++++++++++-------- .../tests/test_algorithms.py | 2 - 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 5378ca7b9..169da3463 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -499,7 +499,6 @@ def bucket_sort(array: Array, **kwargs) -> Array: This function does not support custom comparators as is the case with other sorting functions in this file. - The ouput array doesn't contain any `None` value. """ start = kwargs.get('start', 0) end = kwargs.get('end', len(array) - 1) @@ -557,6 +556,22 @@ def cocktail_sort(array: Array, **kwargs) -> Array: array: Array The array which is to be sorted. + start: int + The starting index of the portion + which is to be sorted. + Optional, by default 0 + end: int + The ending index of the portion which + is to be sorted. + Optional, by default the index + of the last position filled. + comp: lambda/function + The comparator which is to be used + for sorting. If the function returns + False then only swapping is performed. + Optional, by default, less than or + equal to is used for comparing two + values. Returns ======= @@ -581,37 +596,28 @@ def cocktail_sort(array: Array, **kwargs) -> Array: ========== .. [1] https://en.wikipedia.org/wiki/Cocktail_shaker_sort - - Note - ==== - - Since, cocktail sort is a comparison sorting algorithm, - custom comparators aren't allowed. - The ouput array does contain `None` value. But the iteration will be less than or equalt to o(n//2) """ def swap(i, j): array[i], array[j] = array[j], array[i] + lower = kwargs.get('start', 0) upper = kwargs.get('end', len(array) - 1) + comp = kwargs.get("comp", lambda u, v: u <= v) + swapping = False while (not swapping and upper - lower >= 1): + swapping = True for j in range(lower, upper): - if array[j] is None and array[j + 1] is not None: - swap(j + 1, j) - elif array[j + 1] is None or array[j] is None: - continue - elif array[j + 1] < array[j]: + if _comp(array[j], array[j+1], comp) is False: swap(j + 1, j) swapping = False + upper = upper - 1 for j in range(upper, lower, -1): - if array[j - 1] is None and array[j] is not None: - swap(j, j - 1) - elif array[j] is None or array[j - 1] is None: - continue - elif array[j - 1] > array[j]: + if _comp(array[j-1], array[j], comp) is False: swap(j, j - 1) swapping = False lower = lower + 1 + return array diff --git a/pydatastructs/linear_data_structures/tests/test_algorithms.py b/pydatastructs/linear_data_structures/tests/test_algorithms.py index 586fd35ed..f4e87f3cb 100644 --- a/pydatastructs/linear_data_structures/tests/test_algorithms.py +++ b/pydatastructs/linear_data_structures/tests/test_algorithms.py @@ -29,8 +29,6 @@ def _test_common_sort(sort, *args, **kwargs): None, None, None, None, None, None, None, None, None, None, None, None] assert arr._data == expected_arr - if sort!=cocktail_sort: - assert (arr._last_pos_filled, arr._num, arr._size) == (12, 13, 31) n = random.randint(10, 20) arr = OneDimensionalArray(int, n) From 7a4581cac2d448f3115e6802730349fbbd27e487 Mon Sep 17 00:00:00 2001 From: czgdp1807 Date: Wed, 13 Jan 2021 11:24:38 +0530 Subject: [PATCH 36/36] cocktail_sort -> cocktail_shaker_sort --- pydatastructs/linear_data_structures/__init__.py | 2 +- pydatastructs/linear_data_structures/algorithms.py | 10 +++++----- .../linear_data_structures/tests/test_algorithms.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pydatastructs/linear_data_structures/__init__.py b/pydatastructs/linear_data_structures/__init__.py index 07c7629ce..dcf48160d 100644 --- a/pydatastructs/linear_data_structures/__init__.py +++ b/pydatastructs/linear_data_structures/__init__.py @@ -29,6 +29,6 @@ matrix_multiply_parallel, counting_sort, bucket_sort, - cocktail_sort + cocktail_shaker_sort ) __all__.extend(algorithms.__all__) diff --git a/pydatastructs/linear_data_structures/algorithms.py b/pydatastructs/linear_data_structures/algorithms.py index 169da3463..9c656cc0f 100644 --- a/pydatastructs/linear_data_structures/algorithms.py +++ b/pydatastructs/linear_data_structures/algorithms.py @@ -12,7 +12,7 @@ 'matrix_multiply_parallel', 'counting_sort', 'bucket_sort', - 'cocktail_sort' + 'cocktail_shaker_sort' ] def _merge(array, sl, el, sr, er, end, comp): @@ -547,7 +547,7 @@ def bucket_sort(array: Array, **kwargs) -> Array: array._modify(force=True) return array -def cocktail_sort(array: Array, **kwargs) -> Array: +def cocktail_shaker_sort(array: Array, **kwargs) -> Array: """ Performs cocktail sort on the given array. @@ -582,13 +582,13 @@ def cocktail_sort(array: Array, **kwargs) -> Array: Examples ======== - >>> from pydatastructs import OneDimensionalArray as ODA, cocktail_sort + >>> from pydatastructs import OneDimensionalArray as ODA, cocktail_shaker_sort >>> arr = ODA(int, [5, 78, 1, 0]) - >>> out = cocktail_sort(arr) + >>> out = cocktail_shaker_sort(arr) >>> str(out) '[0, 1, 5, 78]' >>> arr = ODA(int, [21, 37, 5]) - >>> out = cocktail_sort(arr) + >>> out = cocktail_shaker_sort(arr) >>> str(out) '[5, 21, 37]' diff --git a/pydatastructs/linear_data_structures/tests/test_algorithms.py b/pydatastructs/linear_data_structures/tests/test_algorithms.py index f4e87f3cb..22eccbb60 100644 --- a/pydatastructs/linear_data_structures/tests/test_algorithms.py +++ b/pydatastructs/linear_data_structures/tests/test_algorithms.py @@ -1,7 +1,7 @@ from pydatastructs import ( merge_sort_parallel, DynamicOneDimensionalArray, OneDimensionalArray, brick_sort, brick_sort_parallel, - heapsort, matrix_multiply_parallel, counting_sort, bucket_sort, cocktail_sort) + heapsort, matrix_multiply_parallel, counting_sort, bucket_sort, cocktail_shaker_sort) from pydatastructs.utils.raises_util import raises import random @@ -69,8 +69,8 @@ def test_counting_sort(): 480, 548, 686, 688, 696, 779] assert counting_sort(arr)._data == expected_arr -def test_cocktail_sort(): - _test_common_sort(cocktail_sort) +def test_cocktail_shaker_sort(): + _test_common_sort(cocktail_shaker_sort) def test_matrix_multiply_parallel(): ODA = OneDimensionalArray