matheusfrancisco / pydsx

Implementation about data structure and algorithms in python
1 stars 0 forks source link

[BUG] Linked List append #2

Closed matheusfrancisco closed 4 years ago

matheusfrancisco commented 4 years ago

We have a problem at singly_linked_list.py at append method:

When we design the append we think of using it with append at the beginning and append at the end

Problem: When we append at end of list it seems that they are duplicating the element at the beginning of the list.

In [2]: from pydsx import SinglyLinkedList
In [3]: l = SinglyLinkedList()
In [4]: l.append(1)
In [8]: l.append(2,tail=True)
In [11]: print(len(l))
for i in l:
    ...:     print(i)
    ...: 
    ...: 
>>2
>>1
>>2

And when the first entry in the list is with tail=True we have this error image

Where to look

pydsx.singly_linked_list.linked_list.py


    def append(self, value, first=True, tail=False):
        if value is None:
            return None
        if first and not tail:
            self._append_first(value)
        if tail:
            self._append_tail(value)

Remember try to write test: tests.test_linked_list.py

Aditya1001001 commented 4 years ago

Can I work on this issue?

matheusfrancisco commented 4 years ago

You can open a pull request.

To run the tests: make test in the root folder

Thank you very much for fixing this bug.