# 1. Introduction

A Doubly Linked List is a type of linked list in which each node contains a data part and two pointers. The two pointers are:

1. A pointer to the next node in the sequence (next).

2. A pointer to the preceding node in the sequence (prev).

It allows for bidirectional traversal, meaning one can navigate both forward and backward.

# 2. Implementation Steps

1. Define the Node class which will represent each element of the list, containing the data and pointers to the previous and next nodes.

2. Implement the DoublyLinkedList class with methods to:

- Add elements to the end (append).

- Remove elements (remove).

- Display the list (display).

3. Write the client code to test the Doubly Linked List implementation.

# 3. Implementation in Scala

``````// Definition for a Doubly-Linked List Node
class Node[A](var data: A, var prev: Node[A] = null, var next: Node[A] = null)
private var head: Node[A] = null
// Append an element to the end of the list
def append(data: A): Unit = {
val newNode = new Node(data)
} else {
while(current.next != null) {
current = current.next
}
current.next = newNode
newNode.prev = current
}
}
// Remove a node from the list
def remove(data: A): Boolean = {
while(current != null) {
if(current.data == data) {
if(current.prev != null) current.prev.next = current.next
if(current.next != null) current.next.prev = current.prev
return true
}
current = current.next
}
false
}
// Display the list
def display(): Unit = {
while(current != null) {
print(current.data + " <-> ")
current = current.next
}
println("null")
}
}
``````

### Client Code:

``````val dll = new DoublyLinkedList[Int]
dll.append(10)
dll.append(20)
dll.append(30)
dll.display()          // Expected: 10 <-> 20 <-> 30 <-> null
dll.remove(20)
dll.display()          // Expected: 10 <-> 30 <-> null
``````

### Output:

```10 <-> 20 <-> 30 <-> null
10 <-> 30 <-> null
```

### Explanation:

1. class Node[A](var data: A, var prev: Node[A] = null, var next: Node[A] = null): This defines our generic Node with data and two pointers for the previous and next nodes.