Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. class Node(object):
  2.     def __init__(self, data=None):
  3.         self.data = data
  4.         self.next = None
  5.    
  6. def sorted_merge(first, second):
  7.         fake = Node(-1)
  8.         current = fake
  9.        
  10.         if first is None and second is None:
  11.             return None
  12.         if first is None:
  13.             return second
  14.         if second is None:
  15.             return first
  16.        
  17.         while(first.next and second.next):
  18.             if(first.data >= second.data):
  19.                 current.next = second
  20.                 current = second
  21.                 second = second.next
  22.             else:
  23.                 current.next = first
  24.                 current = first
  25.                 first = first.next
  26.          
  27.         if first.next is not None:
  28.           current.next = first
  29.         if second.next is not None:
  30.           current.next = second
  31.         print(current)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement