Last active
December 6, 2017 17:33
-
-
Save han8909227/e3ac031d5ec74f3291abb8ec604af514 to your computer and use it in GitHub Desktop.
Partition a Linked List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dl_partition(x, ll): | |
less_list = [] | |
higher_list = [] | |
for node in ll: | |
if node.data >= x: | |
higher_list.append(node.data) | |
else: | |
lower_list.append(node.data) | |
less_list.reverse() | |
higher_list.reverse() | |
result = LinkedList() | |
for val in less_list: | |
result.push(val) | |
for val in higher_list: | |
result.push(val) | |
return result | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment