-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeepCopy_LL.py
More file actions
43 lines (31 loc) · 866 Bytes
/
deepCopy_LL.py
File metadata and controls
43 lines (31 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Problem 1:
You are given a singly Linked List, return a deep copy of the list.
"""
# Definition for a Node.
class Node:
def __init__(self, data, next=None):
self.data = data
self.next = next
def addToList(newNode: Node):
newNode.next
def makeDeepCopy(aList):
prevNode = Node(aList.data)
nextNode = aList.next
while (nextNode != None):
nextNextNode = nextNode.next
nextNode.next = prevNode
prevNode = nextNode
nextNode = nextNextNode
return prevNode
aList = Node(1,Node(2,Node(3,Node(4))))
curNode = aList
while (curNode != None):
print(curNode.data)
curNode = curNode.next
print("asda")
anotherList = makeDeepCopy(aList)
curNode = anotherList
while (curNode != None):
print(curNode.data)
curNode = curNode.next