-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyLinkedList.java
More file actions
58 lines (47 loc) · 1.41 KB
/
Copy pathMyLinkedList.java
File metadata and controls
58 lines (47 loc) · 1.41 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
57
58
public class MyLinkedList<T> {
private Node<T> head = null;
private int size = 0;
public void AddFront(T data) {
Node<T> newNode = new Node<T>(data);
if (head == null) {
head = newNode;
} else {
newNode.next = head;
head = newNode;
}
size++;
}
/**
* Adds a new node to the end of the LinkedList
*/
public void Append(T data) {
Node<T> currentNode = head;
while (currentNode.next != null) {
currentNode = currentNode.next;
}
// once we have our current last node
Node<T> newNode = new Node<T>(data); // create the new node and ensure it's next is null
currentNode.next = newNode; // set the next of the old last node equal to the new node
size++;
}
// 1
public void Insert(int index) {
Node<T> currentNode = head;
int currentIndex = 0;
for (int i = 0; i < index; i++){
}
}
@Override
public String toString() {
Node<T> currentNode = head;
String returnString = "";
while (currentNode != null) {
returnString += " " + currentNode.data.toString();
currentNode = currentNode.next;
}
return returnString;
}
public int GetSize() {
return size;
}
}