Implements clone which duplicates a list. Pay attention, because if there are sublists, they must be duplicated as well. Understand the implementation of the following function, which recursively displays the ids of each node in a list  def show_ids(M, level=0):      k = M.first_node      while k is not None:          print(" "*2*level, id(k))          if (str(k.value.__class__.__name__) == str(M.__class__.__name__)):                           show_ids(k.value, level+1)          k = k.next          W=L2(Node(10, Node(L2(Node(14, Node(15, Node(L2(Node(16, Node(17))))))), Node(20, Node(30)))) ) show_ids(W) Develop your solution as follows: - First copy the nodes of the current list (self) - Create a new list with the copied nodes - Loop through the nodes of the new list checking the value field - If this field is also a list (use isinstance as in the show_ids function) then it calls clone on that list and substitutes the value. Complete the code: def L4(*args,**kwargs):           class L4_class(L):          def clone(self):              def clone_node(node):                  return <... YOUR CODE HERE ...>              r = <... YOUR CODE HERE...>              return r      return L4_class(*args,**kwargs) check your code, both lists have to have the same content, but different ids W=L4(Node(10, Node(L4(Node(14, Node(15, Node(L4(Node(16, Node(17))))))), Node(20, Node(30)))) ) W W.__class__.__name__ K = W.clone() k show_ids(W) show_ids(K)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Implements clone which duplicates a list. Pay attention, because if there are sublists, they must be duplicated as well. Understand the implementation of the following function, which recursively displays the ids of each node in a list 

def show_ids(M, level=0):
     k = M.first_node
     while k is not None:
         print(" "*2*level, id(k))
         if (str(k.value.__class__.__name__) == str(M.__class__.__name__)):
            
             show_ids(k.value, level+1)
         k = k.next
        
W=L2(Node(10, Node(L2(Node(14, Node(15, Node(L2(Node(16, Node(17))))))), Node(20, Node(30)))) )
show_ids(W)

Develop your solution as follows:

- First copy the nodes of the current list (self)

- Create a new list with the copied nodes

- Loop through the nodes of the new list checking the value field

- If this field is also a list (use isinstance as in the show_ids function) then it calls clone on that list and substitutes the value.

Complete the code:

def L4(*args,**kwargs):
    
     class L4_class(L):

         def clone(self):

             def clone_node(node):
                 return <... YOUR CODE HERE ...>

             r = <... YOUR CODE HERE...>
             return r
     return L4_class(*args,**kwargs)

check your code, both lists have to have the same content, but different ids

W=L4(Node(10, Node(L4(Node(14, Node(15, Node(L4(Node(16, Node(17))))))), Node(20, Node(30)))) )
W
W.__class__.__name__
K = W.clone()
k
show_ids(W)
show_ids(K)

Expert Solution
steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Operations of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education