-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
99 lines (80 loc) · 2.09 KB
/
Copy pathLinkedList.java
File metadata and controls
99 lines (80 loc) · 2.09 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
public class Node {
public Node next;
public String item;
}
public class LinkedList{
private int size;
private Node head;
public LinkedList(){
this.size = 0;
this.head = null;
}
public int size(){
return size;
}
public boolean find(String val){
Node node = this.head;
boolean found = false;
for (int i = 0; i < size; i++){
if (node.item.equals(val)){
found = true;
}
node = node.next;
}
return found;
}
public String get(int index){
Node node = this.head;
if (head == null || index > size -1){
throw new IndexOutOfBoundsException();
} else {
for (int i = 0; i < index; i++){
node = node.next;
}
return node.item;
}
}
public void remove(int index){
Node curr = this.head;
Node prev = null;
if (head == null || index > size -1){
throw new IndexOutOfBoundsException();
} else{
for (int i = 0; i < index; i++){
prev = curr;
curr = curr.next;
}
prev.next = curr.next;
this.size--;
}
}
public void add(String val){
Node node = new Node();
node.item = val;
Node curr = this.head;
if (this.head == null){
this.head.next = null;
this.size = 1;
}else{
while(curr.next != null){
curr = curr.next;
}
curr.next = node;
node.next = null;
this.size++;
}
}
get(int index){
//look at index and return the value there
}
set(int index, String valString)
//look at index and change val to valString
add(String val)
// add a link and the element val
// is it empty
insert(int index, String val){
// add val to specifc index
}
remove(int index)
// remove links that are atached to that index
}