-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleLinkedList.java
More file actions
49 lines (32 loc) · 983 Bytes
/
SingleLinkedList.java
File metadata and controls
49 lines (32 loc) · 983 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
package com.employee;
// ************************************ TODO F1 ************************************
/*
* Implement a Singly linkedList
*
*/
// ************************************ SOLUTION F1 BEGIN ************************************
public class SingleLinkedList {
Node head = null;
Node tail = null;
public void addNode(PermanentEmployee employeeAdd) {
// Allocate the node and set next as Null
Node newNode = new Node(employeeAdd);
//Make New node as head on empty linked list
if(head == null) {
head = newNode;
tail = newNode;
}else {
tail.next =newNode;
tail = newNode;
}
}
}
class Node{
public PermanentEmployee employee;
Node next;
Node(PermanentEmployee employee){
this.employee=employee;
this.next = null;
}
}
// ************************************ SOLUTION F1 END ************************************