# Insert node at end of circular doubly linked list

Here given code implementation process.

``````//C Program
//Insert node at end of circular doubly linked list
#include <stdio.h>

#include <stdlib.h> //for malloc function

//create structure
struct Node {
int data;
struct Node *next;
struct Node *prev;
};

struct Node *head = NULL, *tail = NULL;
//Insert Node at end of linked list

//Create a dynamic node
struct Node *node = (struct Node *) malloc(sizeof(struct Node));
if (node == NULL) {
printf("Memory overflow\n");
return;

} else {
//set data value
node->next = node;
node->prev = node;
node->data = value;

tail = node;
} else {
node->prev = tail;
tail->next = node;
tail = node;
}

}
}
//display element from head to tail

} else {
printf("\nNode Form Front to Rear :\n");
//Traverse doubly linked list from front to rear
while (temp != NULL) {
//print node value
printf("%d  ", temp->data);

temp = temp->next;

break;
}

}

}
}
//display element from tail to head

if (tail == NULL) {
} else {
struct Node *temp = tail;
printf("\nNode Form Rear to Front :\n");
//Traverse doubly linked list from rear to front
while (temp != NULL) {
//print node value
printf("%d  ", temp->data);

temp = temp->prev;
if (temp == tail) {
break;
}
}

}
}

int main() {

//Display all node

return 0;
}```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````
``````/*
C++ Program
Insert node at end of circular doubly linked list
*/

#include<iostream>

using namespace std;
class Node {
public:
int data;
Node *next;
Node *prev;
Node(int value) {
this->data = value;
this->next = this;
this->prev = this;
}
};
public:
Node *tail;
this->tail = NULL;
}
Node *node = new Node(value);
if (node == NULL) {
cout << "Memory overflow\n";
return;
} else {
} else {
node->prev = this->tail;
this->tail->next = node;
}
this->tail = node;
}
}
} else {
cout << "\nNode Form Front to Rear :\n";
while (temp != NULL) {
cout << temp->data << "  ";
temp = temp->next;
break;
}
}
}
}
if (this->tail == NULL) {
} else {
Node *temp = this->tail;
cout << "\nNode Form Rear to Front :\n";
while (temp != NULL) {
cout << temp->data << "  ";
temp = temp->prev;
if (temp == this->tail) {
break;
}
}
}
}
};
int main() {
return 0;
}```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````
``````/*
Java Program
Insert node at end of circular doubly linked list
*/
class Node {

public int data;

public Node next;

public Node prev;

public Node(int value) {
//Setup initial values of linked list node
this.data = value;
this.next = this;
this.prev = this;
}
}

public Node tail;

tail = null;
}
Node node = new Node(value);

if (node == null) {

System.out.print("Memory overflow\n");
return;
} else {

} else {
node.prev = tail;
tail.next = node;
}
tail = node;
}
}

} else {

System.out.print("\nNode Form Front to Rear :\n");

while (temp != null) {

System.out.print(temp.data+"  ");
temp = temp.next;

break;
}
}
}
}

if (tail == null) {

} else {
Node temp = tail;

System.out.print("\nNode Form Rear to Front :\n");

while (temp != null) {

System.out.print(temp.data+"  ");
temp = temp.prev;

if (temp == tail) {
break;
}
}
}
}

public static void main(String[] args) {

}
}```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````
``````/*
C# Program
Insert node at end of circular doubly linked list
*/
using System;
public class Node {

public int data;

public Node next;

public Node prev;

public Node(int value) {
//Setup initial values of linked list node
this.data = value;
this.next = this;
this.prev = this;
}
}

public Node tail;

tail = null;
}
Node node = new Node(value);

if (node == null) {

Console.Write("Memory overflow\n");
return;
} else {

} else {
node.prev = tail;
tail.next = node;
}
tail = node;
}
}

} else {

Console.Write("\nNode Form Front to Rear :\n");

while (temp != null) {

Console.Write(temp.data+"  ");
temp = temp.next;

break;
}
}
}
}

if (tail == null) {

} else {
Node temp = tail;

Console.Write("\nNode Form Rear to Front :\n");

while (temp != null) {

Console.Write(temp.data+"  ");
temp = temp.prev;

if (temp == tail) {
break;
}
}
}
}

public static void Main(String[] args) {

}
}```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````
``````# Python 3 Program
# Insert node at end of circular doubly linked list
class Node :

def __init__(self, value) :
self.data = value
self.next = self
self.prev = self

def __init__(self) :
self.tail = None

node = Node(value)
if (node == None) :
print("Memory overflow\n")
return
else :
else :
node.prev = self.tail
self.tail.next = node

self.tail = node

else :
print("\nNode Form Front to Rear :")
while (temp != None) :
print(temp.data ,end="  ")
temp = temp.next
break

if (self.tail == None) :
else :
temp = self.tail
print("\nNode Form Rear to Front :")
while (temp != None) :
print(temp.data ,end="  ")
temp = temp.prev
if (temp == self.tail) :
break

def main() :

if __name__ == "__main__":
main()```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````
``````# Ruby Program
# Insert node at end of circular doubly linked list

class Node
attr_accessor :data, :next, :prev
def initialize(value)
self.data = value
self.next = self
self.prev = self
end
end

def initialize()
@tail = nil
end
node = Node.new(value)
if (node == nil)
print("Memory overflow\n")
return
else
else
node.prev = @tail
@tail.next = node
end
@tail = node
end
end
else
print("\nNode Form Front to Rear  :\n")
while (temp != nil)
print(temp.data ,"  ")
temp = temp.next
break
end
end
end
end
if (@tail == nil)
else
temp = @tail
print("\nNode Form Rear to Front  :\n")
while (temp != nil)
print(temp.data ,"  ")
temp = temp.prev
if (temp == @tail)
break
end
end
end
end
end
def main()
end

main()```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````
``````<?php

/*
Php Program
Insert node at end of circular doubly linked list
*/

class Node {
public \$data;
public \$next;
public \$prev;

function __construct(\$value) {
\$this->data = \$value;
\$this->next = \$this;
\$this->prev = \$this;
}
}
public \$tail;

function __construct() {
\$this->tail = null;
}

\$node = new Node(\$value);
if (\$node == null) {
echo("Memory overflow\n");
return;
} else {
} else {
\$node->prev = \$this->tail;
\$this->tail->next = \$node;
}
\$this->tail = \$node;
}
}

} else {
echo("\nNode Form Front to Rear :\n");
while (\$temp != null) {
echo(\$temp->data ."  ");
\$temp = \$temp->next;
break;
}
}
}
}

if (\$this->tail == null) {
} else {
\$temp = \$this->tail;
echo("\nNode Form Rear to Front :\n");
while (\$temp != null) {
echo(\$temp->data ."  ");
\$temp = \$temp->prev;
if (\$temp == \$this->tail) {
break;
}
}
}
}
}

function main() {
}
main();```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````
``````/*
Node Js Program
Insert node at end of circular doubly linked list
*/

class Node {

constructor(value) {
this.data = value;
this.next = this;
this.prev = this;
}
}

constructor() {
this.tail = null;
}
var node = new Node(value);
if (node == null) {
process.stdout.write("Memory overflow\n");
return;
} else {
} else {
node.prev = this.tail;
this.tail.next = node;
}
this.tail = node;
}
}
} else {
process.stdout.write("\nNode Form Front to Rear :\n");
while (temp != null) {
process.stdout.write(temp.data + "  ");
temp = temp.next;
break;
}
}
}
}
if (this.tail == null) {
} else {
var temp = this.tail;
process.stdout.write("\nNode Form Rear to Front :\n");
while (temp != null) {
process.stdout.write(temp.data + "  ");
temp = temp.prev;
if (temp == this.tail) {
break;
}
}
}
}
}

function main() {
}

main();```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````
``````/*
Swift 4 Program
Insert node at end of circular doubly linked list
*/

class Node {
var data: Int;
var next: Node? ;
var prev: Node? ;
init(_ value: Int) {
self.data = value;
self.next = self;
self.prev = self;
}
}
var tail: Node? ;
init() {
self.tail = nil;
}
let node: Node? = Node(value);
if (node == nil) {
print("Memory overflow\n");
return;
} else {
} else {
node!.prev = self.tail;
self.tail!.next = node;
}
self.tail = node;
}
}
} else {
print("\nNode Form Front to Rear :");
while (temp != nil) {
print(temp!.data ,terminator:"  ");
temp = temp!.next;
break;
}
}
}
}
if (self.tail == nil) {
} else {
var temp: Node? = self.tail;
print("\nNode Form Rear to Front :");
while (temp != nil) {
print(temp!.data ,terminator:"  ");
temp = temp!.prev;
if (temp === self.tail) {
break;
}
}
}
}
}
func main() {
}
main();```
```

#### Output

``````Node Form Front to Rear :
1  2  3  4  5  6
Node Form Rear to Front :
6  5  4  3  2  1 ``````

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.