Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def merge(left,right):
- S=DirectedList()
- S_pos=S.first()
- while not left.isempty() and not right.isempty():
- if left.inspect(left.first()) <= right.inspect(right.first()):
- S.insert(S_pos,left.inspect(left.first())) #ska lägga in elementet på sista plats
- S_pos=S.next(S_pos)
- left.remove(left.first())
- else:
- S.insert(S_pos,right.inspect(right.first())) #samma
- S_pos=S.next(S_pos)
- right.remove(right.first())
- while not left.isempty():
- S.insert(S_pos,left.inspect(left.first())) #samma
- S_pos=S.next(S_pos)
- left.remove(left.first())
- while not right.isempty():
- S.insert(S_pos,right.inspect(right.first())) #samma
- S_pos=S.next(S_pos)
- right.remove(right.first())
- return S
Add Comment
Please, Sign In to add comment