Advertisement
Guest User

Untitled

a guest
Oct 16th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. package no.uib.ii.inf102.f18.mandatory1;
  2.  
  3. public class BSTDebugging {
  4.  
  5.  
  6. public static void main(String[] args) {
  7. Kattio io = new Kattio(System.in);
  8. int n = io.getInt();
  9. int key = io.getInt();
  10. int current = io.getInt();
  11. boolean valid = true;
  12. for(int i = 0; i < n - 1; i++) {
  13. int next = io.getInt();
  14. if(key >= current) {
  15. if(current >= next) {
  16. System.out.println("invalid");
  17. valid = false;
  18. break;
  19. }
  20. }
  21. else if (current == key) {
  22. break;
  23. }
  24. else {
  25. if(current <= next) {
  26. System.out.println("invalid");
  27. valid = false;
  28. break;
  29. }
  30. }
  31. current = next;
  32. }
  33. if(valid == true) {
  34. System.out.println("valid");
  35. }
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement