-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLL.java
More file actions
115 lines (111 loc) · 2.42 KB
/
CLL.java
File metadata and controls
115 lines (111 loc) · 2.42 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.util.*;
class CLL
{
static Scanner sc = new Scanner(System.in);
static Node head;
static Node tail;
static class Node
{
int data;
Node next;
Node(int d)
{
data = d;
next = null;
}
}
public static void create(CLL l,int d)
{
Node nn =new Node(d);
if(head == null)
{
head = nn;
tail = nn;
head.next = head;
return;
}
else
{
Node temp = head;
while(temp.next!=head)
{
temp =temp.next;
}
temp.next = nn;
tail = nn;
nn.next = head;
}
}
public static void display(CLL l)
{
Node t = head;
do
{
System.out.print(t.data+" ");
t=t.next;
}while(t!=head);
}
public static void insert(CLL l , int d)
{
System.out.println("\nInsert at:\n1.Begining\n2.End\n3.B/W");
int ch = sc.nextInt();
Node nn = new Node(d);
switch(ch)
{
case 1:
nn.next = head;
head = nn;
tail.next = head;
break;
case 2:
tail.next = nn;
tail = nn;
tail.next = head;
break;
case 3:
System.out.println("Enter pos:");
int pos = sc.nextInt();
Node t1 = head;
int i=1;
while(pos!=i)
{
t1 = t1.next;
i++;
}
nn.next = t1.next;
t1.next = nn;
break;
}
}
public static void delet(int d)
{
if(head.data == d)
{
head = head.next;
tail.next = head;
return;
}
Node temp = head;
Node b = null;
while(temp.data!=d)
{
b=temp;
temp = temp.next;
}
b.next = temp.next;
temp = null;
}
public static void main(String[] pav)
{
CLL l = new CLL();
create(l,10);
create(l,20);
create(l,30);
display(l);
// insert(l,200);
// display(l);
System.out.println("\n");
delet(20);
display(l);
}
}