-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
63 lines (60 loc) · 987 Bytes
/
LinkedList.java
File metadata and controls
63 lines (60 loc) · 987 Bytes
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
package Daily_Problem;
public class LinkedList {
class Node{
int data;
Node next;
}
public int size=0;
public Node head;
public Node tail;
public void addLast(int data)
{
Node nn=new Node();
nn.data=data;
nn.next=null;
if(size>=1)
{
this.tail.next=nn;
}
if(this.size==0)
{
this.size++;
this.head=nn;
this.tail=nn;
}
else
{
this.size++;
this.tail=nn;
}
}
public void dispaly() {
Node temp=this.head;
while(temp!=null)
{
System.out.println(temp.data);
temp=temp.next;
}
}
public void addFirst(int data)
{
Node nn=new Node();
nn.data=data;
nn.next=null;
if(this.size>=1)
{
nn.next=this.head;
this.head=nn;
}
}
public static void main(String[] args) {
LinkedList obj=new LinkedList();
obj.addLast(1);
obj.addLast(3);
obj.addLast(4);
obj.addLast(6);
obj.addLast(7);
obj.addFirst(9);
obj.dispaly();
}
}