-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularLinkedList.java
More file actions
74 lines (59 loc) · 1.27 KB
/
CircularLinkedList.java
File metadata and controls
74 lines (59 loc) · 1.27 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package technical;
public class CircularLinkedList {
private Listnode last;
private int length;
public class Listnode {
private Listnode next;
private int data;
public Listnode(int data) {
this.data = data;
}
}
public CircularLinkedList() {
last = null;
length = 0;
}
public int length() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public void insertatfirst(int data) {
Listnode temp=new Listnode(data);
if(last==null) {
last=temp;
}else {
temp.next=last.next;
}
last.next=temp;
length++;
}
public void insertatlast(int data) {
Listnode temp=new Listnode(data);
if(last==null) {
last=temp;
last.next=last;
}else {
temp.next=last.next;
last.next=temp;
last=temp;
}
length++;
}
public void createcircularlist() {
Listnode first = new Listnode(1);
Listnode second = new Listnode(23);
Listnode third = new Listnode(55);
Listnode fourth = new Listnode(66);
first.next = second;
second.next = third;
third.next = fourth;
fourth.next = first;
last = fourth;
}
public static void main(String[] args) {
CircularLinkedList csl = new CircularLinkedList();
csl.createcircularlist();
}
}