Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:17:18+00:00 2026-06-17T09:17:18+00:00

Ok A question from assignment says to create an ordered doubly linked list…such that

  • 0

Ok A question from assignment says to create an ordered doubly linked list…such that each object with lexicographically smaller name comes “Before” the other One…Like names in a Dictionary…also objects with same name can be arranged in any order…

To link two objects I have setBefore() and setAfter() method…
and I have done this much…but still don’t know where I’m doing wrong..may be a little guidance from you guys can help me…

atMe is an object that is already present in the doubly linked list and newFrob is an object to be inserted…

def insert(atMe, newFrob):
    if newFrob.myName() < atMe.myName():
        if atMe.getBefore() == None:
            atMe.setBefore(newFrob)
            newFrob.setAfter(atMe)
        elif atMe.getBefore().myName()<newFrob.myName():
            atMe.getBefore().setAfter(newFrob)
            newFrob.setBefore(atMe.getBefore)
            atMe.setBefore(newFrob)
            newFrob.setAfter(atMe)
        else:
            insert(atMe.getBefore(),newFrob)

    elif newFrob.myName() > atMe.myName():
        if atMe.getAfter() == None:
            atMe.setAfter(newFrob)
            newFrob.setBefore(atMe)
        elif atMe.getAfter().myName()>newFrob.myName():
            atMe.getAfter().setBefore(newFrob)
            newFrob.setAfter(atMe.getAfter)
            atMe.setAfter(newFrob)
            newFrob.setBefore(atMe)
        else:
            insert(atMe.getAfter(),newFrob)

    elif newFrob.myName()==atMe.myName():
        if atMe.getAfter() != None:
            newFrob.setAfter(atMe.getAfter())
        newFrob.setBefore(atMe)
        if atMe.getAfter() != None:
            atMe.getAfter().setBefore(newFrob)
        atMe.setAfter(newFrob)

And this is the Frob Class to be used…

class Frob(object):
    def __init__(self, name):
        self.name = name
        self.before = None
        self.after = None
    def setBefore(self, before):
        self.before = before
    def setAfter(self, after):
        self.after = after
    def getBefore(self):
        return self.before
    def getAfter(self):
        return self.after
    def myName(self):
        return self.name

where Before and After are links to left and right objects in double linked list…
objects from this class are to be inserted to double linked list…

Example:

a=Frob('foo')
b=Frob('bar')
c=Frob('frob')
d=Frob('code')

code                             output
insert(a,b)                   bar->foo
insert(a,c)                   bar->foo->frob
insert(b,d)                   bar->code->foo->frob

now suppose

code                             output
insert(b,Frob('code'))        bar->code->code->foo->frob
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:17:18+00:00Added an answer on June 17, 2026 at 9:17 am

    The issue is in this line (and an equivalent one when you’re moving the other direction):

    newFrob.setBefore(atMe.getBefore)
    

    You’re missing a set of parentheses after atMe.getBefore, so you end up passing the bound method itself to newFrob.setBefore rather than the value that would be returned by that method. This is an easy typo to make, so I wouldn’t feel too bad about missing it on your assignment.

    I found the error by trying the following sequence of inserts and inspecting the values (I’ve summarized the ones that worked OK with comments):

    >>> a = Frob("a")
    >>> b = Frob("b")
    >>> c = Frob("c")
    >>> d = Frob("d")
    >>> insert(a, b) # list is a<->b
    >>> insert(a, d) # list is a<->b<->d
    >>> insert(a, c) # list is a<->b<->c->?
    >>> c.getAfter()
    <bound method Frob.getAfter of <__main__.Frob object at 0x000000000318EBA8>>
    

    That object mentioned at the end is b, which lead me to find the error in the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an assignment question from school: Create a recursive method called toBinary that
I have a linked list question that stems from this homework prompt I am
Question from an exam: Given a linked list with unknown size n , where
This is an assignment question I received from school. The question says, write a
I've this question from an assignment to create a Store which rent out books,
Question from Object-Oriented JavaScript book: Imagine Array() doesn't exist and the array literal notation
Full Question: From a child table linked to a row in its grandparent table
First question from me; I'm currently fixing a graphing service that uses XSLFO to
This is a follow up question from Problem with array assignment I now have
Follow up question to : Populate a list property from delimited string The problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.