Doubly linked list class

The doubly linked list class captures the data on which our functions will be operating. For the size method, we set the count instance variable to 0; it can be used to keep track of the number of items in the linked list. head and tail will point to the head and tail of the list when we begin to insert nodes into the list. Consider the following Python code for creating a class:

class DoublyLinkedList(object):
def init (self):
self.head = None
self.tail = None
self.count = 0
We adopt a new convention where self.head points to the beginner node of the list and self.tail points to the latest node added to the list. This is contrary to the convention we used in the singly linked list. There are no fixed rules as to the naming of the head and tail node pointers.

Doubly linked lists also require functionalities that return the size of the list, insert items into the list, and also delete nodes from the list. We will be discussing and providing important functionalities and code on the doubly linked list in the following subsections. Let's start with the append operation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset