Created
January 12, 2013 18:03
-
-
Save mooreniemi/4519630 to your computer and use it in GitHub Desktop.
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 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