File tree 1 file changed +50
-0
lines changed 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class Main {
2
+ public static void main (String [] args ) {
3
+ Main Obj = new Main ();
4
+ Obj .add (11 );
5
+ Obj .add (22 );
6
+ Obj .add (33 );
7
+ Obj .add (44 );
8
+ Obj .add (55 );
9
+ Obj .print ();
10
+ }
11
+ public class Node {
12
+ int element ;
13
+ Node next ;
14
+ public Node (int element ) {
15
+ this .element = element ;
16
+ }
17
+ }
18
+
19
+ public Node head = null ;
20
+ public Node tail = null ;
21
+
22
+ public void add (int element ){
23
+ Node newEle = new Node (element );
24
+ if (head == null ) {
25
+ head = newEle ;
26
+ tail = newEle ;
27
+ newEle .next = head ;
28
+ }
29
+ else {
30
+ tail .next = newEle ;
31
+ tail = newEle ;
32
+ tail .next = head ;
33
+ }
34
+ }
35
+
36
+ public void print () { //print function
37
+ Node current = head ;
38
+ if (head == null ) {
39
+ System .out .println ("List is empty" );
40
+ }
41
+ else {
42
+ System .out .println ("Nodes of the circular linked list: " );
43
+ do {
44
+ System .out .print (" " + current .element );
45
+ current = current .next ;
46
+ }while (current != head );
47
+ System .out .println ();
48
+ }
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments