## Brossh Interview Question

Developer Program Engineers**Country:**Isreal

**Interview Type:**Written Test

I implemented a simple double linked list in Python:

```
class Node:
def __init__(self, value=None, left=None, right=None):
self.value = value
self.left = left
self.right = right
def append(self, value):
if self.right is not None:
self.right.append(value)
else:
self.right = Node(value, self)
def remove(self, value):
if self.value == value:
if self.left is not None:
self.left.right = self.right
else:
self.value = self.right.value
self.right = self.right.right
self.right.left = self
if self.right is not None:
self.right.remove(value)
def as_list(self):
ret_list = list()
Node._as_list(self, ret_list)
return ret_list
@staticmethod
def _as_list(node, ret_list):
ret_list.append(node.value)
if node.right is not None:
Node._as_list(node.right, ret_list)
class DLinkedList:
def __init__(self, numbers_list=None):
self.root = DLinkedList._generate_nodes(numbers_list if numbers_list is not None else [])
@staticmethod
def _generate_nodes(numbers_list):
if len(numbers_list) == 0:
return None
root = None
for number in numbers_list:
if root is None:
root = Node(number)
else:
root.append(number)
return root
def as_list(self):
if self.root is None:
return []
return self.root.as_list()
def remove(self, element):
if self.root is None:
return
return self.root.remove(element)
dlinked_list = DLinkedList([1, 2, 43, 1, 56, 12, 5, 1, -2, 4333, 3])
print(dlinked_list.as_list())
dlinked_list.remove(43)
print(dlinked_list.as_list())
dlinked_list.remove(1)
print(dlinked_list.as_list())
```

Search google for "doubly linked list in c", doubly linked list is quite commonly asked question.

- PeyarTheriyaa December 10, 2018the one from tutorials point is good enough and quite exhaustive.

ignore functions you don't need and comments