Skip to content Skip to sidebar Skip to footer

Adding To A Linked List

Can someone please tell me why my add function is not working: (it only adds the first {'a', 3} but not the rest) thankyou class Frequency(object): ''' Stores a letter:freq

Solution 1:

The problem is that after the first loop current is always None, therefore the second loop body is never executed even in case found is False.


Solution 2:

it seems to me that there is another issue. when found is false and current.frequency > frequency, you should set current.next.next to the previous next, something like : temp = current.next current.next=Frequency( current.next.next=temp


Solution 3:

This is the right time to learn how to use the Python debugger ! You can learn a lot if you use it. Write a testscript which fails and start the debugger with python -m pdb testscript.py. Doug Hellmann writes nice articles about python modules, you should read the one about the pdb module.


Post a Comment for "Adding To A Linked List"