fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. public class Node {
  12.  
  13. public Node left, right;
  14. public int elem;
  15.  
  16. public Node (int val) {
  17. this.elem = val;
  18. }
  19.  
  20. void insert(int val){
  21. if(this.elem < val){
  22. if(this.right != null){
  23. this.right.insert(val);
  24. }
  25. else{
  26. this.right = new Node(val);
  27. }
  28. }
  29. else if(this.elem > val){
  30. if(this.left != null){
  31. this.left.insert(val);
  32. }
  33. else{
  34. this.left = new Node(val);
  35.  
  36. }
  37. }
  38. else {
  39. return;
  40. }
  41. }
  42.  
  43. }
  44.  
  45. public void run () {
  46. Random rand = new Random();
  47. Node n = new Node(500000);
  48. for(int i = 0; i < 100000; i++) {
  49. n.insert(rand.nextInt(1000000));
  50. }
  51. }
  52.  
  53. public static void main (String[] args) throws java.lang.Exception {
  54. long t = System.currentTimeMillis();
  55. new Ideone().run();
  56. System.out.println(System.currentTimeMillis()-t);
  57. }
  58. }
Success #stdin #stdout 0.15s 320256KB
stdin
Standard input is empty
stdout
45