Skip to content

Instantly share code, notes, and snippets.

@han8909227
Last active December 6, 2017 17:33
Show Gist options
  • Save han8909227/e3ac031d5ec74f3291abb8ec604af514 to your computer and use it in GitHub Desktop.
Save han8909227/e3ac031d5ec74f3291abb8ec604af514 to your computer and use it in GitHub Desktop.
Partition a Linked List
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