-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
39 lines (34 loc) · 815 Bytes
/
LinkedList.java
File metadata and controls
39 lines (34 loc) · 815 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
package leetcode.practice;
import java.io.PrintWriter;
public class LinkedList {
Node head; // head of lisl
Node lastNode;
/* Linked list Node*/
/* Utility functions */
/* Inserts a new Node at front of the list. */
public void addToTheLast(Node node)
{
if (head == null)
{
head = node;
lastNode = node;
}
else
{
Node temp = head;
lastNode.next = node;
lastNode = node;
}
}
/* Function to print linked list */
void printList()
{
Node temp = head;
while (temp != null)
{
System.out.print(temp.data+" ");
temp = temp.next;
}
System.out.println();
}
}