-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathLinkedList.java
More file actions
70 lines (51 loc) · 1.24 KB
/
LinkedList.java
File metadata and controls
70 lines (51 loc) · 1.24 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
public class LinkedList {
public Node head=new Node();
public Node tail=new Node();
public void addToTail(int data) {
//your code is here
Node node1=new Node();
node1.value=data;
if(head.next==null){
head.next=node1;
}
if(tail.next!=null){
tail.next.next=node1;
}
tail.next=node1;
}
public boolean contains(int value) {
//your code is here
Node node1 =head;
while(node1.next!=null){
if(node1.value==value){
return true;
}
node1=node1.next;
}
if(node1.value==value){
return true;
}
return false;
}
public int removeHead() {
//your code is here
if(head.next!=null){
if(head.next.next==null){
tail.next=null;
}
Node node1=head.next;
head.next=node1.next;
return node1.value;
}
else {
return 0;}
}
public void printList() {
//your code is here
}
public class Node {
//your code is here
public int value ;
public Node next;
}
}