forked from prabhupant/python-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraversal.py
More file actions
43 lines (34 loc) · 706 Bytes
/
Copy pathtraversal.py
File metadata and controls
43 lines (34 loc) · 706 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
class Node():
def __init__(self, val):
self.val = val
self.next = None
def push(head, val):
if not head:
head = Node(val)
head.next = head
return
curr = head
while curr:
if curr.next == head:
break
curr = curr.next
curr.next = Node(val)
curr.next.next = head
def print_list(head):
if not head:
return
curr = head
while curr:
print(curr.val, end=" ")
curr = curr.next
if curr == head:
break
first = Node(1)
second = Node(2)
third = Node(3)
first.next = second
second.next = third
third.next = first
print_list(first)
push(first, 4)
print_list(first)