Created
June 18, 2017 08:50
-
-
Save shreezan123/fa1091b5cd69abbb13fd8fa0fdf4dbb5 to your computer and use it in GitHub Desktop.
Take input from txt file and perform respective job in the tree
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package lab5; | |
import java.util.Scanner; | |
public class DataCenterOrders { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int numOperations = in.nextInt(); | |
// create object of BinarySearchTree class | |
BinarySearchTree tree1 = new BinarySearchTree(); | |
// TODO: Define any data structures that you will need here. | |
for (int i = 0; i < numOperations; ++i) { | |
String op = in.next(); | |
if (op.contentEquals("Insert")) { | |
int dataCenterSize = in.nextInt(); | |
// insert the value stored in the variable dataCenterSize | |
tree1.insert(dataCenterSize); | |
// TODO: Insert dataCenterSize into your data structure. | |
System.out.println("Inserted " + dataCenterSize); | |
} | |
else if (op.contentEquals("Range")) { | |
int min = in.nextInt(); | |
int max = in.nextInt(); | |
int count = 0; | |
// System.out.println(min); | |
// System.out.println(max); | |
int totalmax = tree1.numLessthan(max); | |
int totalmin = tree1.numLessthan(min); | |
// From max and min, we are getting two values and we have to | |
// find the number of items in the tree within those values | |
count = totalmax - totalmin; | |
// TODO: Set count to the number of data center of sizes | |
// greater than or equal to min, but less than max. | |
System.out.println("Range " + min + " " + max + " - Result: " + count); | |
} else if (op.contentEquals("Delete")) { | |
int dataCenterSize = in.nextInt(); | |
// first delete the value by calling method delete | |
tree1.delete(dataCenterSize); | |
// TODO: Delete dataCenterSize from your data structure. | |
System.out.println("Deleted " + dataCenterSize); | |
} else { | |
System.err.println("Unknown operation: " + op); | |
System.exit(1); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment