Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package no.uib.ii.inf102.f18.mandatory1;
- public class BSTDebugging {
- public static void main(String[] args) {
- Kattio io = new Kattio(System.in);
- int n = io.getInt();
- int key = io.getInt();
- int current = io.getInt();
- boolean valid = true;
- for(int i = 0; i < n - 1; i++) {
- int next = io.getInt();
- if(key >= current) {
- if(current >= next) {
- System.out.println("invalid");
- valid = false;
- break;
- }
- }
- else if (current == key) {
- break;
- }
- else {
- if(current <= next) {
- System.out.println("invalid");
- valid = false;
- break;
- }
- }
- current = next;
- }
- if(valid == true) {
- System.out.println("valid");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement