Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node:
- def __init__(self,data):
- self.data=data
- self.next=None
- cur=root=Node(-1)
- #creeate linked list
- #[2,14,100]
- #[13,15,17,19]
- for i in [2,13,14,15,17,19,100]:
- cur.next=Node(i)
- cur=cur.next
- root=root.next
- def display(x):
- while x!=None:
- print(x.data,end=" ")
- x=x.next
- print()
- def separate(root):
- odd_head = odd = Node(-1)
- even_head = even = Node(-1)
- cur=root
- while cur!=None:
- if cur.data%2==0:
- even.next=cur
- even=even.next
- else:
- odd.next=cur
- odd=odd.next
- cur=cur.next
- odd.next=None
- even.next=None
- return odd_head.next,even_head.next
- display(root)
- odd_head,even_head=separate(root)
- display(odd_head)
- display(even_head)
Advertisement
Add Comment
Please, Sign In to add comment