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. class TernarySearchTree
  11. {
  12. char data;
  13. TernarySearchTree left,right,mid;
  14. boolean end;
  15.  
  16. public TernarySearchTree(char data,boolean end,TernarySearchTree left,TernarySearchTree right,TernarySearchTree mid)
  17. {
  18. this.data=data;
  19. this.end=end;
  20. this.left=left;
  21. this.mid=mid;
  22. this.right=right;
  23. }
  24. }
  25.  
  26. public TernarySearchTree searchPosition(TernarySearchTree root,String word)
  27. {
  28. if(root==null)
  29. return insert(root,word);
  30.  
  31. if(word.charAt(0)>root.data)
  32. root.right=searchPosition(root.right,word);
  33.  
  34. else if(word.charAt(0)<root.data)
  35. root.left=searchPosition(root.left,word);
  36.  
  37. else
  38. {
  39. if(word.length()==1)
  40. root.end=true;
  41. else
  42. root.mid=searchPosition(root.mid,word.substring(1));
  43.  
  44. }
  45. return root;
  46. }
  47. public TernarySearchTree insert(TernarySearchTree root,String word)
  48. {
  49. root=new TernarySearchTree(word.charAt(0),false,null,null,null);
  50.  
  51. if(word.length()==1)
  52. root.end=true;
  53. else
  54. root.mid=insert(root.mid,word.substring(1));
  55.  
  56. return root;
  57. }
  58.  
  59. public boolean searchTernarySearchTree(TernarySearchTree root,String word)
  60. {
  61. if(root==null)
  62. return false;
  63.  
  64. if(word.charAt(0)>root.data)
  65. return searchTernarySearchTree(root.right,word);
  66. else if(word.charAt(0)<root.data)
  67. return searchTernarySearchTree(root.left,word);
  68. else
  69. {
  70. if(word.length()==1)
  71. {
  72. if(root.end)
  73. return true;
  74. else
  75. return false;
  76. }
  77. else
  78. return searchTernarySearchTree(root.mid,word.substring(1));
  79. }
  80.  
  81. }
  82.  
  83. public void ternarySearchTreeUtil()
  84. {
  85. TernarySearchTree root=null;
  86.  
  87. par=searchPosition(root,"BOAT");
  88.  
  89. searchPosition(par,"BOATS");
  90.  
  91. searchPosition(par,"BOA");
  92. searchPosition(par,"BOSS");
  93.  
  94. searchPosition(par,"BOOM");
  95. searchPosition(par,"BOOK");
  96. searchPosition(par,"MAN");
  97. System.out.println(searchTernarySearchTree(par,"BOOK"));
  98.  
  99.  
  100. }
  101. public static void main (String[] args) throws java.lang.Exception
  102. {
  103. // your code goes here
  104. }
  105. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:87: error: cannot find symbol
		par=searchPosition(root,"BOAT");
		^
  symbol:   variable par
  location: class Ideone
Main.java:89: error: cannot find symbol
		searchPosition(par,"BOATS");
		               ^
  symbol:   variable par
  location: class Ideone
Main.java:91: error: cannot find symbol
		searchPosition(par,"BOA");
		               ^
  symbol:   variable par
  location: class Ideone
Main.java:92: error: cannot find symbol
		searchPosition(par,"BOSS");
		               ^
  symbol:   variable par
  location: class Ideone
Main.java:94: error: cannot find symbol
		searchPosition(par,"BOOM");
		               ^
  symbol:   variable par
  location: class Ideone
Main.java:95: error: cannot find symbol
		searchPosition(par,"BOOK");
		               ^
  symbol:   variable par
  location: class Ideone
Main.java:96: error: cannot find symbol
		searchPosition(par,"MAN");
		               ^
  symbol:   variable par
  location: class Ideone
Main.java:97: error: cannot find symbol
		System.out.println(searchTernarySearchTree(par,"BOOK"));
		                                           ^
  symbol:   variable par
  location: class Ideone
8 errors
stdout
Standard output is empty