Skip to content

Instantly share code, notes, and snippets.

@chelseadole
Created December 6, 2017 17:43
Show Gist options
  • Save chelseadole/7bd04b51a8c0d02345467d2e33e057f7 to your computer and use it in GitHub Desktop.
Save chelseadole/7bd04b51a8c0d02345467d2e33e057f7 to your computer and use it in GitHub Desktop.
"""Gist to organize LinkedList. All vals higher than x go after "x", all vals lower go before."""
# NOTE: I'm not totally sure these work... there was an issue with my LinkedList and I wasn't able to properly test
# This version is solved using lists:
def org_list(x, link):
"""."""
new_list = LinkedList()
while link.head is not None:
if link.head.val < x:
new_list.push(link.pop())
elif link.head.val >= x:
curr = link.head
while curr.val < link.head.val:
curr = curr.next
new_list.push(link.pop())
return new_list
# This version is solved without built-in lists
def org_list1(x, link):
"""Organize LL around x."""
vals = []
while link.head is not None:
vals.append(link.pop())
vals.append(x)
vals = vals.sort()
new_list = LinkedList([vals])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment