# Insert node at end of circular linked list

In this post are given an example of how to insert new created nodes of end of circular linked list.

Generally there are two way to solve this problem. method 1 Using of single pointer . And method 2 using of two pointer variables.

Method 1: This method are normally used because we are assume that linked list are contain initial node (assumption to add new node to existing list). So this method are useful. First we are need to find last nodes of linked list. But note that in circular linked list last node, next pointer always hold the reference of first linked list node.

So start iteration from head of linked list and check next upcoming node is not a head. When this condition are satisfied then visit next upcoming node. When condition are fail, That means this is a last node of circular list. And add new node to last position , and assign to this inserted next pointer field to reference of head node of linked list.

Test Cases: There is following test case are useful.

1) In case linked list are empty then create new linked list node and assign this address to head pointer of linked list. But note that Circular linked list last node connect to first node by next pointer. So in this case assign the newly created node address is to next pointer .

2) When linked list are not empty then find last linked list node. This process are requires O(n) time. And add new node to last position connect last node to head node by using of last node next pointer fields.

Time complexity of this method are O(n) (Note that We are reducing this complexity in next method). Suppose we are inserted the following (1,2,3,4,5,6,7,8) node in a sequence.

Here given code implementation process.

// Java Program
// Insert node at last of circular linked lists

// Define class of linked list Node
{
public int data;
{
this.data = data;
this.next = first;
}
}
{
// Class constructors
{
}
// Insert node at end of circular linked list
public void insert(int value)
{
// Create a node
if (this.head == null)
{
// First node of linked list
}
else
{
// Find last node
while (temp.next != this.head)
{
// Visit to next node
temp = temp.next;
}
// Add new node at the last
temp.next = node;
}
}
// Display node element of circular linked list
public void display()
{
if (this.head == null)
{
}
else
{
System.out.print("Linked List Element :");
// iterate linked list
while (temp != null)
{
// Display node
System.out.print("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == head)
{
// Stop iteration
return;
}
}
}
}
public static void main(String[] args)
{
// Display node
}
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Include header file
#include <iostream>
using namespace std;
// C++ Program
// Insert node at last of circular linked lists

// Define class of linked list Node
{
public: int data;
{
this->data = data;
this->next = first;
}
};
{
// Class constructors
{
}
// Insert node at end of circular linked list
void insert(int value)
{
// Create a node
if (this->head == NULL)
{
// First node of linked list
}
else
{
// Find last node
while (temp->next != this->head)
{
// Visit to next node
temp = temp->next;
}
// Add new node at the last
temp->next = node;
}
}
// Display node element of circular linked list
void display()
{
if (this->head == NULL)
{
cout << "Empty Linked List" << endl;
}
else
{
cout << "Linked List Element :";
// iterate linked list
while (temp != NULL)
{
// Display node
cout << "  " << temp->data;
// Visit to next node
temp = temp->next;
if (temp == this->head)
{
// Stop iteration
return;
}
}
}
}
};
int main()
{
// Display node
return 0;
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// C Program
// Insert node at last of circular linked lists
#include <stdio.h>
// for malloc function
#include <stdlib.h>

{
int data;
};
{
};
// Returns the new linked list
{
// Create memory of head and tail Nodes
struct CircularLinkedList *cll = (struct CircularLinkedList *)
if (cll == NULL)
{
printf("Memory overflow\n");
}
else
{
}
return cll;
}
// Insert node at end of circular linked list
void insert(struct CircularLinkedList *cll, int value)
{
// Create a node
struct LinkNode *node = (struct LinkNode *)
if (node == NULL)
{
// Overflow
return;
}
node->data = value;
if (cll->head == NULL)
{
// First node of linked list
}
else
{
// Find last node
while (temp->next != cll->head)
{
// Visit to next node
temp = temp->next;
}
// Add new node at the last
temp->next = node;

}
}
//display element of linked list
{
if (head == NULL)
{
}
else
{
printf("Linked List Element : ");
while (temp)
{
printf("%d  ", temp->data);
// visit to next node
temp = temp->next;
if (temp == head)
{
break; //terminate loop
}
}
}
}
int main()
{
// Create node pointer
// insert element of linked list
insert(cll, 1);
insert(cll, 2);
insert(cll, 3);
insert(cll, 4);
insert(cll, 5);
insert(cll, 6);
insert(cll, 7);
insert(cll, 8);
// display all nodes
return 0;
}

#### Output

Linked List Element : 1  2  3  4  5  6  7  8
package main
import "fmt"
// Go Program
// Insert node at last of circular linked lists

// Define class of linked list Node
type LinkNode struct {
data int
}
return me
}
type CircularLinkedList struct {
}
return me
}
// Insert node at end of circular linked list
func(this *CircularLinkedList) insert(value int) {
// Create a node
if this.head == nil {
// First node of linked list
} else {
// Find last node
for (temp.next != this.head) {
// Visit to next node
temp = temp.next
}
// Add new node at the last
temp.next = node
}
}
// Display node element of circular linked list
func(this CircularLinkedList) display() {
if this.head == nil {
} else {
fmt.Print("Linked List Element :")
// iterate linked list
for (temp != nil) {
// Display node
fmt.Print("  ", temp.data)
// Visit to next node
temp = temp.next
if temp == this.head {
// Stop iteration
return
}
}
}
}
func main() {
// Display node
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Include namespace system
using System;
// Csharp Program
// Insert node at last of circular linked lists

// Define class of linked list Node
{
public int data;
{
this.data = data;
this.next = first;
}
}
{
// Class constructors
{
}
// Insert node at end of circular linked list
public void insert(int value)
{
// Create a node
if (this.head == null)
{
// First node of linked list
}
else
{
// Find last node
while (temp.next != this.head)
{
// Visit to next node
temp = temp.next;
}
// Add new node at the last
temp.next = node;
}
}
// Display node element of circular linked list
public void display()
{
if (this.head == null)
{
}
else
{
Console.Write("Linked List Element :");
// iterate linked list
while (temp != null)
{
// Display node
Console.Write("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == this.head)
{
// Stop iteration
return;
}
}
}
}
public static void Main(string[] args)
{
// Display node
}
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
<?php
// Php Program
// Insert node at last of circular linked lists

// Define class of linked list Node
{
public \$data;
public \$next;
public  function __construct(\$data, \$first)
{
\$this->data = \$data;
\$this->next = \$first;
}
}

{
// Class constructors
function __construct()
{
}
// Insert node at end of circular linked list
public  function insert(\$value)
{
// Create a node
if (\$this->head == NULL)
{
// First node of linked list
}
else
{
// Find last node
while (\$temp->next != \$this->head)
{
// Visit to next node
\$temp = \$temp->next;
}
// Add new node at the last
\$temp->next = \$node;
}
}
// Display node element of circular linked list
public  function display()
{
if (\$this->head == NULL)
{
printf("%s\n", "Empty Linked List");
}
else
{
printf("%s", "Linked List Element :");
// iterate linked list
while (\$temp != NULL)
{
// Display node
printf("%s", "  ".strval(\$temp->data));
// Visit to next node
\$temp = \$temp->next;
if (\$temp == \$this->head)
{
// Stop iteration
return;
}
}
}
}
public static
function main(\$args)
{
// Display node
}
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Node JS Program
// Insert node at last of circular linked lists

// Define class of linked list Node
{
constructor(data, first)
{
this.data = data;
this.next = first;
}
}
{
// Class constructors
constructor()
{
}
// Insert node at end of circular linked list
insert(value)
{
// Create a node
if (this.head == null)
{
// First node of linked list
}
else
{
var temp = this.head;
// Find last node
while (temp.next != this.head)
{
// Visit to next node
temp = temp.next;
}
// Add new node at the last
temp.next = node;
}
}
// Display node element of circular linked list
display()
{
if (this.head == null)
{
}
else
{
process.stdout.write("Linked List Element :");
var temp = this.head;
// iterate linked list
while (temp != null)
{
// Display node
process.stdout.write("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == this.head)
{
// Stop iteration
return;
}
}
}
}
}

function main()
{
// Display node
}
main();

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
#  Python 3 Program
#  Insert node at last of circular linked lists

#  Define class of linked list Node
def __init__(self, data, first) :
self.data = data
self.next = first

#  Class constructors
def __init__(self) :

#  Insert node at end of circular linked list
def insert(self, value) :
#  Create a node
if (self.head == None) :
#  First node of linked list
else :
#  Find last node
while (temp.next != self.head) :
#  Visit to next node
temp = temp.next

#  Add new node at the last
temp.next = node

#  Display node element of circular linked list
def display(self) :
if (self.head == None) :
else :
print("Linked List Element :", end = "")
#  iterate linked list
while (temp != None) :
#  Display node
print("  ", temp.data, end = "")
#  Visit to next node
temp = temp.next
if (temp == self.head) :
#  Stop iteration
return

def main() :
#  Display node

if __name__ == "__main__": main()

#### Output

Linked List Element :   1   2   3   4   5   6   7   8
#  Ruby Program
#  Insert node at last of circular linked lists

#  Define class of linked list Node
# Define the accessor and reader of class LinkNode
attr_accessor :data, :next
def initialize(data, first)
self.data = data
self.next = first
end

end

# Define the accessor and reader of class CircularLinkedList
#  Class constructors
def initialize()
end

#  Insert node at end of circular linked list
def insert(value)
#  Create a node
if (self.head == nil)
#  First node of linked list
else

#  Find last node
while (temp.next != self.head)
#  Visit to next node
temp = temp.next
end

#  Add new node at the last
temp.next = node
end

end

#  Display node element of circular linked list
def display()
if (self.head == nil)
print("Empty Linked List", "\n")
else

print("Linked List Element :")
#  iterate linked list
while (temp != nil)
#  Display node
print("  ", temp.data)
#  Visit to next node
temp = temp.next
if (temp == self.head)
#  Stop iteration
return
end

end

end

end

end

def main()
#  Display node
end

main()

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Scala Program
// Insert node at last of circular linked lists

// Define class of linked list Node
class LinkNode(var data: Int,
{
// Class constructors
def this()
{
this(null);
}
// Insert node at end of circular linked list
def insert(value: Int): Unit = {
// Create a node
if (this.head == null)
{
// First node of linked list
}
else
{
// Find last node
while (temp.next != this.head)
{
// Visit to next node
temp = temp.next;
}
// Add new node at the last
temp.next = node;
}
}
// Display node element of circular linked list
def display(): Unit = {
if (this.head == null)
{
}
else
{
print("Linked List Element :");
// iterate linked list
while (temp != null)
{
// Display node
print("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == head)
{
// Stop iteration
return;
}
}
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
// Display node
}
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Swift 4 Program
// Insert node at last of circular linked lists

// Define class of linked list Node
{
var data: Int;
var next: LinkNode? ;
init(_ data: Int, _ first: LinkNode? )
{
self.data = data;
self.next = first;
}
}
{
// Class constructors
init()
{
}
// Insert node at end of circular linked list
func insert(_ value: Int)
{
// Create a node
if (self.head == nil)
{
// First node of linked list
}
else
{
// Find last node
while (!(temp!.next === self.head))
{
// Visit to next node
temp = temp!.next;
}
// Add new node at the last
temp!.next = node;
}
}
// Display node element of circular linked list
func display()
{
if (self.head == nil)
{
}
else
{
print("Linked List Element :", terminator: "");
// iterate linked list
while (temp  != nil)
{
// Display node
print("  ", temp!.data, terminator: "");
// Visit to next node
temp = temp!.next;
if (temp === self.head)
{
// Stop iteration
return;
}
}
}
}
}
func main()
{
// Display node
}
main();

#### Output

Linked List Element :   1   2   3   4   5   6   7   8
// Kotlin Program
// Insert node at last of circular linked lists

// Define class of linked list Node
{
var data: Int;
var next: LinkNode ? ;
constructor(data: Int, first: LinkNode ? )
{
this.data = data;
this.next = first;
}
}
{
// Class constructors
constructor()
{
}
// Insert node at end of circular linked list
fun insert(value: Int): Unit
{
// Create a node
if (this.head == null)
{
// First node of linked list
}
else
{
// Find last node
while (temp?.next != this.head)
{
// Visit to next node
temp = temp?.next;
}
// Add new node at the last
temp?.next = node;
}
}
// Display node element of circular linked list
fun display(): Unit
{
if (this.head == null)
{
}
else
{
print("Linked List Element :");
// iterate linked list
while (temp != null)
{
// Display node
print("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == this.head)
{
// Stop iteration
return;
}
}
}
}
}
fun main(args: Array < String > ): Unit
{
// Display node
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8

Method 2 : In this scenario used two pointer head and tail. head are store the reference of first inserted nodes. And tail are store the reference of current insert linked list node.

// Java Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
{
public int data;
{
this.data = data;
this.next = first;
}
}
{
// Class constructors
{
this.tail = null;
}
// Insert node at end of circular linked list
public void insert(int value)
{
// Create a node
if (this.head == null)
{
// First node of linked list
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
// Display node element of circular linked list
public void display()
{
if (this.head == null)
{
}
else
{
System.out.print("Linked List Element :");
// iterate linked list
while (temp != null)
{
// Display node
System.out.print("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == head)
{
// Stop iteration
return;
}
}
}
}
public static void main(String[] args)
{
// Display node
}
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Include namespace system
using System;
// Csharp Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
{
public int data;
{
this.data = data;
this.next = first;
}
}
{
// Class constructors
{
this.tail = null;
}
// Insert node at end of circular linked list
public void insert(int value)
{
// Create a node
if (this.head == null)
{
// First node of linked list
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
// Display node element of circular linked list
public void display()
{
if (this.head == null)
{
}
else
{
Console.Write("Linked List Element :");
// iterate linked list
while (temp != null)
{
// Display node
Console.Write("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == this.head)
{
// Stop iteration
return;
}
}
}
}
public static void Main(string[] args)
{
// Display node
}
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Include header file
#include <iostream>
using namespace std;
// C++ Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
{
public: int data;
{
this->data = data;
this->next = first;
}
};
{
// Class constructors
{
this->tail = NULL;
}
// Insert node at end of circular linked list
void insert(int value)
{
// Create a node
if (this->head == NULL)
{
// First node of linked list
this->tail = node;
}
else
{
this->tail->next = node;
this->tail = node;
}
}
// Display node element of circular linked list
void display()
{
if (this->head == NULL)
{
cout << "Empty Linked List" << endl;
}
else
{
cout << "Linked List Element :";
// iterate linked list
while (temp != NULL)
{
// Display node
cout << "  " << temp->data;
// Visit to next node
temp = temp->next;
if (temp == this->head)
{
// Stop iteration
return;
}
}
}
}
};
int main()
{
// Display node
return 0;
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// C Program
// Insert node at last of circular linked lists using tail pointer
#include <stdio.h>
// for malloc function
#include <stdlib.h>

{
int data;
};
{
};
// Returns the new linked list
{
// Create memory of head and tail Nodes
struct CircularLinkedList *cll = (struct CircularLinkedList *)
if (cll == NULL)
{
printf("Memory overflow\n");
}
else
{
cll->tail = NULL;
}
return cll;
}
// Insert node at end of circular linked list
void insert(struct CircularLinkedList *cll, int value)
{
// Create a node
if (node == NULL)
{
// Overflow
return;
}
node->data = value;
if (cll->head == NULL)
{
// First node of linked list
cll->tail = node;
}
else
{
cll->tail->next = node;

// New tail node
cll->tail = node;

}
}
//display element of linked list
{
if (head == NULL)
{
}
else
{
printf("Linked List Element : ");
while (temp)
{
printf("%d  ", temp->data);
// visit to next node
temp = temp->next;
if (temp == head)
{
break; //terminate loop
}
}
}
}
int main()
{
// Create node pointer
// insert element of linked list
insert(cll, 1);
insert(cll, 2);
insert(cll, 3);
insert(cll, 4);
insert(cll, 5);
insert(cll, 6);
insert(cll, 7);
insert(cll, 8);
// display all nodes
return 0;
}

#### Output

Linked List Element : 1  2  3  4  5  6  7  8
package main
import "fmt"
// Go Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
type LinkNode struct {
data int
}
me.data = data
me.next = first
return me
}
type CircularLinkedList struct {
}
me.tail = nil
return me
}
// Insert node at end of circular linked list
func(this *CircularLinkedList) insert(value int) {
// Create a node
if this.head == nil {
// First node of linked list
this.tail = node
} else {
this.tail.next = node
this.tail = node
}
}
// Display node element of circular linked list
func(this CircularLinkedList) display() {
if this.head == nil {
} else {
fmt.Print("Linked List Element :")
// iterate linked list
for (temp != nil) {
// Display node
fmt.Print(" ", temp.data)
// Visit to next node
temp = temp.next
if temp == this.head {
// Stop iteration
return
}
}
}
}
func main() {
// Display node
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
<?php
// Php Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
{
public \$data;
public \$next;
public  function __construct(\$data, \$first)
{
\$this->data = \$data;
\$this->next = \$first;
}
}
{
public \$tail;
// Class constructors
function __construct()
{
\$this->tail = NULL;
}
// Insert node at end of circular linked list
public  function insert(\$value)
{
// Create a node
if (\$this->head == NULL)
{
// First node of linked list
\$this->tail = \$node;
}
else
{
\$this->tail->next = \$node;
\$this->tail = \$node;
}
}
// Display node element of circular linked list
public  function display()
{
if (\$this->head == NULL)
{
printf("%s\n", "Empty Linked List");
}
else
{
printf("%s", "Linked List Element :");
// iterate linked list
while (\$temp != NULL)
{
// Display node
printf("%s", "  ".strval(\$temp->data));
// Visit to next node
\$temp = \$temp->next;
if (\$temp == \$this->head)
{
// Stop iteration
return;
}
}
}
}
public static
function main(\$args)
{
// Display node
}
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Node JS Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
{
constructor(data, first)
{
this.data = data;
this.next = first;
}
}
{
// Class constructors
constructor()
{
this.tail = null;
}
// Insert node at end of circular linked list
insert(value)
{
// Create a node
if (this.head == null)
{
// First node of linked list
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
// Display node element of circular linked list
display()
{
if (this.head == null)
{
}
else
{
process.stdout.write("Linked List Element :");
var temp = this.head;
// iterate linked list
while (temp != null)
{
// Display node
process.stdout.write("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == this.head)
{
// Stop iteration
return;
}
}
}
}
}

function main()
{
// Display node
}
main();

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
#  Python 3 Program
#  Insert node at last of circular linked lists using tail

#  Define class of linked list Node
def __init__(self, data, first) :
self.data = data
self.next = first

#  Class constructors
def __init__(self) :
self.tail = None

#  Insert node at end of circular linked list
def insert(self, value) :
#  Create a node
if (self.head == None) :
#  First node of linked list
self.tail = node
else :
self.tail.next = node
self.tail = node

#  Display node element of circular linked list
def display(self) :
if (self.head == None) :
else :
print("Linked List Element :", end = "")
#  iterate linked list
while (temp != None) :
#  Display node
print(" ", temp.data, end = "")
#  Visit to next node
temp = temp.next
if (temp == self.head) :
#  Stop iteration
return

def main() :
#  Display node

if __name__ == "__main__": main()

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
#  Ruby Program
#  Insert node at last of circular linked lists using tail

#  Define class of linked list Node
# Define the accessor and reader of class LinkNode
attr_accessor :data, :next
def initialize(data, first)
self.data = data
self.next = first
end

end

# Define the accessor and reader of class CircularLinkedList
#  Class constructors
def initialize()
self.tail = nil
end

#  Insert node at end of circular linked list
def insert(value)
#  Create a node
if (self.head == nil)
#  First node of linked list
self.tail = node
else

self.tail.next = node
self.tail = node
end

end

#  Display node element of circular linked list
def display()
if (self.head == nil)
print("Empty Linked List", "\n")
else

print("Linked List Element :")
#  iterate linked list
while (temp != nil)
#  Display node
print("  ", temp.data)
#  Visit to next node
temp = temp.next
if (temp == self.head)
#  Stop iteration
return
end

end

end

end

end

def main()
#  Display node
end

main()

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Scala Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
class LinkNode(var data: Int,
{
// Class constructors
def this()
{
this(null, null);
}
// Insert node at end of circular linked list
def insert(value: Int): Unit = {
// Create a node
if (this.head == null)
{
// First node of linked list
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
// Display node element of circular linked list
def display(): Unit = {
if (this.head == null)
{
}
else
{
print("Linked List Element :");
// iterate linked list
while (temp != null)
{
// Display node
print("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == head)
{
// Stop iteration
return;
}
}
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
// Display node
}
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Swift 4 Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
{
var data: Int;
var next: LinkNode? ;
init(_ data: Int, _ first: LinkNode? )
{
self.data = data;
self.next = first;
}
}
{
var tail: LinkNode? ;
// Class constructors
init()
{
self.tail = nil;
}
// Insert node at end of circular linked list
func insert(_ value: Int)
{
// Create a node
if (self.head == nil)
{
// First node of linked list
self.tail = node;
}
else
{
self.tail!.next = node;
self.tail = node;
}
}
// Display node element of circular linked list
func display()
{
if (self.head == nil)
{
}
else
{
print("Linked List Element :", terminator: "");
// iterate linked list
while (temp  != nil)
{
// Display node
print(" ", temp!.data, terminator: "");
// Visit to next node
temp = temp!.next;
if (temp === self.head)
{
// Stop iteration
return;
}
}
}
}
}
func main()
{
// Display node
}
main();

#### Output

Linked List Element :  1  2  3  4  5  6  7  8
// Kotlin Program
// Insert node at last of circular linked lists using tail

// Define class of linked list Node
{
var data: Int;
var next: LinkNode ? ;
constructor(data: Int, first: LinkNode ? )
{
this.data = data;
this.next = first;
}
}
{
var tail: LinkNode ? ;
// Class constructors
constructor()
{
this.tail = null;
}
// Insert node at end of circular linked list
fun insert(value: Int): Unit
{
// Create a node
if (this.head == null)
{
// First node of linked list
this.tail = node;
}
else
{
this.tail?.next = node;
this.tail = node;
}
}
// Display node element of circular linked list
fun display(): Unit
{
if (this.head == null)
{
}
else
{
print("Linked List Element :");
// iterate linked list
while (temp != null)
{
// Display node
print("  " + temp.data);
// Visit to next node
temp = temp.next;
if (temp == this.head)
{
// Stop iteration
return;
}
}
}
}
}
fun main(args: Array < String > ): Unit
{
// Display node
}

#### Output

Linked List Element :  1  2  3  4  5  6  7  8

### Don't stop learning

Animation of circular linked list

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.