-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCircularll.java
More file actions
60 lines (53 loc) · 1.54 KB
/
Circularll.java
File metadata and controls
60 lines (53 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.*;
class Circularll{
private class Node{
private int value;
private Node next;
public Node(int value){ //Constructor
this.value = value;
}
public Node(int value, Node next){ //Dynamic Constructor
this.value =value;
this.next = next;
}
}
private Node head;
private Node tail;
public void insertLast(int val){
Node node= new Node(val);
if(head==null || tail==null){
head=node;
tail=node;
}
tail.next=node;
node.next=head;
tail=node;
}
public void display(){
Node node = head;
if(head!=null){
do{
System.out.print(node.value + "->");
node=node.next;
}while(node != head);
}
System.out.println("HEAD");
}
public void delete(int val){
Node node=head;
if(node == null)
return;
if(node.value == val){
head=head.next;
tail.next=head;
}
do{
Node n= node.next;
if(n.value == val){
node.next=n.next;
break;
}
node= node.next;
}while(node!=head);
}
}