Content-Length: 1260 | pFad | http://github.com/codebasics/data-structures-algorithms-python/pull/42.patch

thub.com From b0affed21b7387e0025ca95a251ca09e02d1d225 Mon Sep 17 00:00:00 2001 From: nehakumari7100 <92616190+nehakumari7100@users.noreply.github.com> Date: Sat, 16 Oct 2021 09:31:32 +0530 Subject: [PATCH] Update 3_linked_list.py We could have defined insert_values method in this way to create a linked list from a list. --- data_structures/3_LinkedList/3_linked_list.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/data_structures/3_LinkedList/3_linked_list.py b/data_structures/3_LinkedList/3_linked_list.py index a6d9466..23267c5 100644 --- a/data_structures/3_LinkedList/3_linked_list.py +++ b/data_structures/3_LinkedList/3_linked_list.py @@ -79,11 +79,16 @@ def remove_at(self, index): itr = itr.next count+=1 - + def insert_values(self, data_list): - self.head = None - for data in data_list: - self.insert_at_end(data) + self.head= None + self.head = Node(data_list[0], None) + for data in range(1, len(data_list)): + itr = self.head + while itr.next: + itr = itr.next + + itr.next = Node(data_list[data], None) if __name__ == '__main__':








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/codebasics/data-structures-algorithms-python/pull/42.patch

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy