# 1. Introduction

A Circular Linked List is a variant of the standard linked list where the last node of the list points back to the first node instead of having a null reference. This cyclic nature can be useful in certain scenarios like representing a cycle in a graph or simulating a round-robin scheduling algorithm.

# 2. Implementation Steps

1. Define the Node class which will represent each element of the list, containing the data and a pointer to the next node.

2. Implement the CircularLinkedList class with methods to:

- Remove elements (remove).

- Display the list (display).

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

# 3. Implementation in Scala

``````// Definition for a Node in Circular Linked List
class Node[A](var data: A, var next: Node[A] = null)

private var head: Node[A] = null
private var tail: Node[A] = null

// Add an element to the list
def add(data: A): Unit = {
val newNode = new Node(data)
tail = newNode
} else {
tail.next = newNode
tail = newNode
}
}

// Remove an element from the list
def remove(data: A): Boolean = {
if (head == null) return false
var prev: Node[A] = null
do {
if (current.data == data) {
if (prev == null) {
tail.next = current.next
} else {
prev.next = current.next
if (current == tail) tail = prev
}
return true
}
prev = current
current = current.next
false
}

// Display the list
def display(): Unit = {
do {
print(current.data + " -> ")
current = current.next
println("back to " + current.data)
}
}
``````

### Client Code:

``````val cll = new CircularLinkedList[Int]
cll.display()          // Expected: 10 -> 20 -> 30 -> back to 10
cll.remove(20)
cll.display()          // Expected: 10 -> 30 -> back to 10
``````

### Output:

```10 -> 20 -> 30 -> back to 10
10 -> 30 -> back to 10
```

### Explanation:

1. class Node[A](var data: A, var next: Node[A] = null): This is our generic Node with data and a single pointer for the next node.