From da576dbf923206264864d1e3e408e6bd85771a69 Mon Sep 17 00:00:00 2001 From: AasheeshLikePanner Date: Sat, 14 Oct 2023 22:28:18 +0530 Subject: [PATCH] Adding doctests in simpson_rule.py --- data_structures/linked_list/swap_nodes.py | 26 +++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/data_structures/linked_list/swap_nodes.py b/data_structures/linked_list/swap_nodes.py index 31dcb02bfa9a..7f6004637a12 100644 --- a/data_structures/linked_list/swap_nodes.py +++ b/data_structures/linked_list/swap_nodes.py @@ -47,10 +47,32 @@ def swap_nodes(self, node_data_1, node_data_2) -> None: Args: node_data_1: Data value of the first node to be swapped. node_data_2: Data value of the second node to be swapped. - - Note: If either of the specified data values isn't found then, no swapping occurs. + Example 1: Swapping two nodes in the middle of the list + >>> ll = LinkedList() + >>> ll.push(1) + >>> ll.push(2) + >>> ll.push(3) + >>> ll.swap_nodes(2, 3) + >>> ll.print_list() + 2 3 1 + Example 2: Swapping nodes at the beginning and end of the list + >>> ll = LinkedList() + >>> ll.push(1) + >>> ll.push(2) + >>> ll.push(3) + >>> ll.swap_nodes(1, 3) + >>> ll.print_list() + 3 2 1 + Example 3: No swapping occurs if one of the data values is not found + >>> ll = LinkedList() + >>> ll.push(1) + >>> ll.push(2) + >>> ll.push(3) + >>> ll.swap_nodes(1, 2) + >>> ll.print_list() + 2 1 3 """ if node_data_1 == node_data_2: return