Repository: codesankalp/dsalgo

Issue:
Insert an item in front of a doubly linked list
Currently there is a `doubly_linked_list.py` file in dsalgo (not merged yet) folder but there is no way to insert an item in front of a given doubly linked list for example, if function name is `insert_start()` (this is preferred name) 

then:
- [ ] code for which items.insert_start([_this contains required object_]) will show up the new object added in front of the doubly linked list created previously in continuation with issue #67 
- [ ] make a pull request for queue branch not for master branch.
- [ ] update the queue branch with the master.

P.S : Refer [this](https://github.com/codesankalp/dsalgo/pull/57/commits/a9e3e248d7d5745b00661f46ed5324c9f0ea17e2) commit for doubly_linked_list.py file. 
or the issue #56 in continuation with issue #67 


Comments:

Patch:
diff --git a/dsalgo/doubly_linked_list.py b/dsalgo/doubly_linked_list.py
new file mode 100644
index 0000000..fb339ba
--- /dev/null
+++ b/dsalgo/doubly_linked_list.py
@@ -0,0 +1,59 @@
+class Node(object):
+    # Doubly linked node
+    def __init__(self, data=None, next=None, prev=None):
+        self.data = data
+        self.next = next
+        self.prev = prev
+
+
+class doubly_linked_list(object):
+    # Use items = doubly_linked_list()
+    def __init__(self):
+        self.head = None
+        self.tail = None
+        self.count = 0
+
+    def append(self, data):
+        # items.append_item() append elements any number of times
+        new_item = Node(data, None, None)
+        if self.head is None:
+            self.head = new_item
+            self.tail = self.head
+        else:
+            new_item.prev = self.tail
+            self.tail.next = new_item
+            self.tail = new_item
+        self.count += 1
+
+    def prepend(self, data):
+        # Insert a node in the beginning
+        new_item = Node(data, None, None)
+        new_item.next = self.head
+        self.head = new_item
+        if self.tail is None:
+            self.tail = self.head
+        self.count += 1
+
+    def print_foward(self):
+        #  to print the output use items.print_foward()
+        for node in self.__iter():
+            print(node)
+
+    def size(self):
+        return self.count
+
+    def __iter(self):
+        # Iterate the list
+        current = self.head
+        while current:
+            item_val = current.data
+            current = current.next
+            yield item_val
+
+    def to_list(self):
+        current_node = self.head
+        arr = []
+        while current_node is not None:
+            arr.append(current_node.data)
+            current_node = current_node.next
+        return arr


Test patch:
diff --git a/tests/test_doubly_linked_list.py b/tests/test_doubly_linked_list.py
new file mode 100644
index 0000000..fb507b9
--- /dev/null
+++ b/tests/test_doubly_linked_list.py
@@ -0,0 +1,27 @@
+import unittest
+from dsalgo.doubly_linked_list import (
+    doubly_linked_list as dll)
+import random
+
+
+class TestDoublyLinkedList(unittest.TestCase):
+
+    def setUp(self):
+        self.test_array = \
+            [random.randint(-100, 100) for _ in range(random.randint(0, 100))]
+
+    def test_append(self):
+        self.dll = dll()
+        for i in self.test_array:
+            self.dll.append(i)
+        self.assertEqual(self.dll.to_list(), self.test_array)
+
+    def test_prepend(self):
+        self.dll = dll()
+        for i in self.test_array:
+            self.dll.prepend(i)
+        self.assertEqual(self.dll.to_list(), self.test_array[::-1])
+
+    def test_size(self):
+        self.test_append()
+        self.assertEqual(self.dll.size(), len(self.test_array))