-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtreesearch.java
More file actions
79 lines (70 loc) · 3.05 KB
/
treesearch.java
File metadata and controls
79 lines (70 loc) · 3.05 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
import java.io.*;
import java.util.ArrayList;
public class treesearch{
public static void main(String[] args) {
bPlusTree tree = new bPlusTree();
try (BufferedReader br = new BufferedReader(new FileReader(args[0]))) {
int order = Integer.parseInt(br.readLine());
//Initializing a bPlusTree with the input order
tree.Initialize(order);
//creating a print writer object and output textfile to print output to a file
PrintWriter out = new PrintWriter(new FileWriter("output_file.txt"));
//Scanning the input file line by line and performing the operations written in the file
String line;
while ((line = br.readLine()) != null) {
if(line.charAt(0)=='I'){
int i=7;
String key = "";
String value = "";
while(line.charAt(i)!=','){
key = key + line.charAt(i);
i++;
}
i++;
while(line.charAt(i)!=')'){
value = value + line.charAt(i);
i++;
}
tree.insertData(Double.parseDouble(key), value);
}
if(line.charAt(0)=='S'){
int i=7;
String key1 = "";
String key2 = "";
while(line.charAt(i)!=','&&line.charAt(i)!=')'){
key1 = key1 + line.charAt(i);
i++;
}
if(line.charAt(i)==','){
i++;
while(line.charAt(i)!=')'){
key2 = key2 + line.charAt(i);
i++;
}
}
if(key2==""){
String result = tree.searchValue(Double.parseDouble(key1));
if(result == null){
out.println("Null");
}
else{
out.println(result);
}
}
else{
ArrayList<String> result = tree.searchValue(Double.parseDouble(key1),Double.parseDouble(key2));
if(result.size() == 0){
out.println("Null");
}
else{
out.println(result.toString().substring(1, result.toString().length()-1));
}
}
}
}
out.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}