-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedList.java
More file actions
72 lines (56 loc) · 1.04 KB
/
linkedList.java
File metadata and controls
72 lines (56 loc) · 1.04 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public class linkedList {
int data;
linkedList next = null;
public linkedList(int i){
this.data = i;
}
void appendToTail(int i){
linkedList n = new linkedList(i);
linkedList old = this;
while (old.next != null){
old = old.next;
}
old.next = n;
old = old.next;
}
void deleteAllIntegerNodes(int i){
linkedList old = this;
if (old.data == i){
old = old.next;
}
while (old.next != null){
if (old.next.data == i){
old.next = old.next.next;
}
old = old.next;
}
}
int getLength(){
if ((this == null) && (this.next == null)){
return 0;
}
int length = 1;
linkedList n = this;
while (n.next != null){
length++;
}
return length;
}
void deleteIndexedNode(int i){
int length = this.getLength();
linkedList n = this;
int temp = 1;
if (length == 0){
return;
}
if (i > length){
System.out.println("The associated index is over the length.");
}
while (n.next != null){
if (temp == i){
n.next = n.next.next;
return;
}
}
}
}