From d2a25f16cca049ed1f1b06cd5d25a677144f4ea4 Mon Sep 17 00:00:00 2001 From: Vinay Sagar <64737008+vinay-sagar123@users.noreply.github.com> Date: Sun, 26 May 2024 14:13:10 +0530 Subject: [PATCH] Update Linked-list.md new change --- contrib/ds-algorithms/Linked-list.md | 39 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/contrib/ds-algorithms/Linked-list.md b/contrib/ds-algorithms/Linked-list.md index d3d7ec1..a660b1c 100644 --- a/contrib/ds-algorithms/Linked-list.md +++ b/contrib/ds-algorithms/Linked-list.md @@ -104,28 +104,27 @@ Lets complete the code and create a linked list. Connect all the code. -if __name__ == '__main__': - llist = LinkedList() - - # Insert words at the beginning - llist.insertAtBeginning(4) # <4> - llist.insertAtBeginning(3) # <3> 4 - llist.insertAtBeginning(2) # <2> 3 4 - llist.insertAtBeginning(1) # <1> 2 3 4 - - # Insert a word at the end - llist.insertAtEnd(10) # 1 2 3 4 <10> - llist.insertAtEnd(7) # 1 2 3 4 10 <7> - - #Insert at a random position - llist.insertAtPosition(9,4) ## 1 2 3 <9> 4 10 7 - # Print the list - llist.printList() + if __name__ == '__main__': + llist = LinkedList() + + # Insert words at the beginning + llist.insertAtBeginning(4) # <4> + llist.insertAtBeginning(3) # <3> 4 + llist.insertAtBeginning(2) # <2> 3 4 + llist.insertAtBeginning(1) # <1> 2 3 4 + + # Insert a word at the end + llist.insertAtEnd(10) # 1 2 3 4 <10> + llist.insertAtEnd(7) # 1 2 3 4 10 <7> + + #Insert at a random position + llist.insertAtPosition(9,4) ## 1 2 3 <9> 4 10 7 + # Print the list + llist.printList() - - output: - 1 2 3 9 4 10 7 +## output: +1 2 3 9 4 10 7 ### Deleting a node from the beginning of a linked list