-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
48 lines (38 loc) · 1.02 KB
/
LinkedList.java
File metadata and controls
48 lines (38 loc) · 1.02 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
package final_project;
import java.util.Arrays;
public class LinkedList {
Node head;
int size = 0;
static class Node {
float[] data;
Node next;
// Constructor
Node(float[] d) {
data = d;
next = null;
}
}
public void insert(float[] data) {
Node new_node = new Node(data);
new_node.next = null;
if (this.head == null) {
this.head = new_node;
} else {
Node last = this.head;
while (last.next != null) {
last = last.next;
}
last.next = new_node;
}
size++;
}
public void printList(LinkedList list) {
Node currNode = list.head;
System.out.print("\nLinkedList: ");
while (currNode != null) {
System.out.print(Arrays.toString(currNode.data) + " ");
currNode = currNode.next;
}
System.out.println("\n");
}
}