Beispiel #1
0
 def remove(self, elem):
     node = Node(elem)
     if self.__my_list.head().get_element() == node.get_element():
         self.__my_list.remove_head()
         return 1
     p = self.__my_list.head()
     if p is not None:
         while p.get_next() is not None:
             if p.get_next().get_element() == node.get_element():
                 p.set_next(p.get_next().get_next())
                 return 1
             p = p.get_next()
     return 0
Beispiel #2
0
 def add(self, elem):
     ''' add an element to the set but make sure that the element is not already in the set (do not raise an error)
     '''
     node = Node(elem)
     p = self.__my_list.head()
     while p is not None:
         if p.get_element() == node.get_element():
             return 0
         p = p.get_next()
     self.__my_list.add_head(node)
     return 1