so i have two classes - one is a book library that is implemented as a doubly linked list and the other class is a DLL node class for a book node which is this:
class Book:
def __init__(self,name,author,dateadded,viewed = False, nextnode=None, prevnode=None):
self._name = name
self._author = author
self._dateadded = dateadded
self._viewed = viewed
self._next = nextnode
self._prev = prevnode
def __str__(self):
""" Return string representation of book """
outstr = ""
outstr += self._name + " /n"
outstr += self._author + "/n"
outstr += self._dateadded
return outstr
def read(self):
""" Simulates the book being read & return string representation of the book """
self._viewed = True
outstr = "CURRENTLY READING: "
outstr += self._name
return outstr
my book library class which deals with a sequence of the book nodes, looks like this:
class BookLibrary:
""" A Doubly Linked List implementing a book library """
def __init__(self):
self.size = 0
self.head = None
self.tail = None
the problem im having is within my add_book() method - when i run it the error im getting is TypeError: add_book() takes 1 positional argument but 5 were given . This is the function itself, I dont really know where im going wrong :(
def add_book(book):
""" Add a book to the library in decreasing order of dateadded """
n = Book(book)
if self.size == 0:
self.head = n
self.tail = n
current_book = n
self.size += 1
elif self.head._dateadded <= n._dateadded:
n._next = self.head
self.head._prev = n
n._prev = None
self.head = n
self.size += 1
elif self.tail._dateadded <= n._dateadded:
self.tail._prev._next = n
n._prev = self.tail._prev
n._next = self.tail
self.tail._prev = n
self.size += 1
elif self.size != 0:
iterator = self.head._next
while iterator._next is not None:
if n._dateadded >= iterator._dateadded:
n._prev = iterator._prev
iterator._prev._next = n
n._next = iterator
iterator._prev = n
self.size += 1
break
else:
iterator = iterator._next
return None
i would really appreciate any help thank you
this is the code i run:
book_lib = BookLibrary()
book_lib.add_book("Harry Potter", "JK ROWLING", 19990101, False)