Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
Created January 12, 2013 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mooreniemi/4519630 to your computer and use it in GitHub Desktop.
Save mooreniemi/4519630 to your computer and use it in GitHub Desktop.
def insert(atMe, newFrob):
"""
atMe: a Frob that is part of a doubly linked list
newFrob: a Frob with no link
This procedure appropriately inserts newFrob into the linked list that atMe is a part of.
"""
# Your Code Here
if newFrob.myName() < atMe.myName():
if atMe.getBefore() == None:
atMe.setBefore(newFrob)
else:
atMe = atMe.getBefore()
atMe.setAfter(newFrob)
elif newFrob.myName() > atMe.myName():
if atMe.getAfter() == None:
atMe.setAfter(newFrob)
else:
atMe = atMe.getAfter()
atMe.setBefore(newFrob)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment