-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSinglyStringLinkedList.java
More file actions
56 lines (36 loc) · 1.05 KB
/
SinglyStringLinkedList.java
File metadata and controls
56 lines (36 loc) · 1.05 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
49
50
51
52
53
54
55
56
package com.java.cci.practice;
public class SinglyStringLinkedList {
private Node firstNode;
private int size;
private class Node {
private String value;
private Node node;
public Node(String value, Node node) {
this.value = value;
this.node = node;
}
}
public boolean prepend(String value) {
Node newNode = null;
if (firstNode == null) {
newNode = new Node(value, null);
} else {
newNode = new Node(value, firstNode.node);
}
firstNode = newNode;
size++;
return true;
}
public boolean append(String value) {
Node newNode = new Node(value, null);
while(firstNode !=null && firstNode.node != null) {
if (firstNode.node == null){
firstNode.node = newNode;
size++;
}
}
return true;
}
public static void main(String args []) {
}
}