-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
55 lines (39 loc) · 747 Bytes
/
LinkedList.java
File metadata and controls
55 lines (39 loc) · 747 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
package linkedList;
public class LinkedList {
class Node{
int data;
Node next;
}
public Node head;
private Node tail;
private int size;
/*Traversing LinkedList */
public void display() {
Node temp = this.head;
while(temp != null) {
System.out.println(temp.data);
temp = temp.next;
}
System.out.println("Size of LinkedList = "+ this.size);
}
public void addLast(int a) {
Node temp = head;
Node nn = new Node();
nn.data = a;
nn.next = null;
//attach
if(this.size >=1) {
this.tail.next = nn ;
}
//Summary Object update
if(this.size == 0) {
this.head = nn;
this.tail = nn;
this.size++;
}
else {
this.tail = nn ;
this.size ++;
}
}
}