Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
83 lines (62 loc) · 2.48 KB
/
Copy pathMain.java
File metadata and controls
83 lines (62 loc) · 2.48 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
import java.io.IOException;
import java.util.ArrayList;
class Main extends SearchObject {
public static void main(String[] args) {
ArrayList<Tweet> myList = null;
try {
myList = TweetLoader.loadAsArrayList("tweet_data.csv");
} catch (IOException e) {
System.out.println(e);
}
Tweet[] newArray = new Tweet[100];
try {
newArray = TweetLoader.loadAsArray("tweet_data_sorted.csv");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Implement the main method according the the program specification
printHead(myList, 8);
printTail(myList, 8);
printHead(newArray, 8);
printTail(newArray, 8);
System.out.println(linearSearch(newArray, newArray.length, new Tweet(1000, "", "")));
System.out.println(linearSearch(newArray, newArray.length, new Tweet(1005, "", "")));
System.out.println(linearSearch(newArray, newArray.length, new Tweet(1804, "", "")));
System.out.println(linearSearch(newArray, newArray.length, new Tweet(2499, "", "")));
System.out.println(linearSearch(newArray, newArray.length, new Tweet(2504, "", "")));
System.out.println(linearSearch(newArray, newArray.length, new Tweet(2800, "", "")));
System.out.println(binarySearch(newArray, newArray.length, new Tweet(1000, "", "")));
System.out.println(binarySearch(newArray, newArray.length, new Tweet(1005, "", "")));
System.out.println(binarySearch(newArray, newArray.length, new Tweet(1804, "", "")));
System.out.println(binarySearch(newArray, newArray.length, new Tweet(2499, "", "")));
System.out.println(binarySearch(newArray, newArray.length, new Tweet(2504, "", "")));
System.out.println(binarySearch(newArray, newArray.length, new Tweet(2800, "", "")));
Tweet a = new Tweet(10, "pos", "hello");
Student b = new Student("Trevin", "Bachan", 99);
Node<Tweet> anode = new Node<Tweet>(a, null);
Node<Student> bnode = new Node<Student>(b, null);
}
public static void printHead(ArrayList<Tweet> list, int n) {
for (int i = 0; i < n; i++) {
System.out.println(list.get(i));
}
}
public static void printHead(Tweet[] list, int n) {
for (int i = 0; i < n; i++) {
System.out.println(list[i]);
}
}
public static void printTail(ArrayList<Tweet> list, int n) {
int s = list.size();
for (int i = s - n; i < s; i++) {
System.out.println(list.get(i));
}
}
public static void printTail(Tweet[] list, int n) {
int s = list.length;
for (int i = s - n; i < s; i++) {
System.out.println(list[i]);
}
}
} // end of Main class