# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# along with this program; if not, please see
+# <http://www.gnu.org/licenses/>
"""Simple implementation of a doubly linked list"""
import collections
data = ""
self._data = data
-
def delete(self):
"""Delete node"""
if self.prev:
- self.prev.next = self.__next__
- if self.__next__:
+ self.prev.next = self.next
+ if self.next:
self.next.prev = self.prev
self._data = None
def __next__(self):
ret = self._next
if ret:
- self._next = ret.__next__
+ self._next = ret.next
else:
raise StopIteration
return ret
+ def next(self):
+ return self.__next__()
+
class LinkedList(collections.abc.Iterable):
"""Doubly linked list"""
>>> [str(data) for data in list]
['foo', 'baz', 'bar']
"""
- new = LinkedListNode(data, prev_node=node, next_node=node.__next__)
- if node.__next__:
+ new = LinkedListNode(data, prev_node=node, next_node=node.next)
+ if node.next:
node.next.prev = new
else:
self._last = new
"""
ret = node.prev
if node is self._first:
- ret = self._first = self._first.__next__
+ ret = self._first = self._first.next
if node is self._last:
self._last = self._last.prev
node.delete()
return ret
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
+