forked from rbk-org/Java_DataStructures
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.java
More file actions
52 lines (46 loc) · 1.14 KB
/
Copy pathLinkedList.java
File metadata and controls
52 lines (46 loc) · 1.14 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
import java.util.ArrayList;
public class LinkedList {
ArrayList<Integer> array = new ArrayList<Integer>(20);
public void addToTail(int data) {
//your code is here
array.add(data);
}
//
public boolean contains(int value) {
//your code is here
int length = array.size();
for (int x = 0; x < length; x++)
if (array.get(x) == value){
return true;
}
return false;
}
//
public void removeHead() {
//your code is here
array.remove(0);
System.out.println(array);
}
//
public void printList() {
//your code is here
System.out.println(array);
}
//
public int getHead() {
//your code is here
return array.get(0);
}
//
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.addToTail(5);
list.addToTail(2);
list.addToTail(-2);
System.out.println("Is the head, and it's been removed");
System.out.println(list.getHead() + " This is the new head");
list.addToTail(3);
list.addToTail(1000);
System.out.println(list.contains(1000));
}
}