fork download
  1. package garden
  2.  
  3. def elements: Int
  4. def insert(x: String): Tree
  5. }
  6.  
  7. case object Tree {
  8. def apply(): Tree = Empty
  9. def apply(a: String): Tree = Leaf1(a)
  10. def apply(a: String, b: String): Tree = Leaf2(a, b)
  11. def apply(a: String, b: String, c: String): Tree = Internal1(Leaf1(a), b, Leaf1(c))
  12. }
  13.  
  14. case object Empty extends Tree {
  15. override def elements = 0
  16.  
  17. def insert(x: String): Tree = Leaf1(x)
  18.  
  19. override def toString = "()"
  20. }
  21.  
  22. case class Leaf1(a: String) extends Tree {
  23. override def elements = 1
  24.  
  25. def insert(x: String): Tree = {
  26. val order = x.compareTo(a)
  27. if (order < 0) Leaf2(x, a)
  28. else if (order > 0) Leaf2(a, x)
  29. }
  30.  
  31. override def toString = "(" + a + ")"
  32. }
  33.  
  34. case class Leaf2(a: String, b: String) extends Tree {
  35. override def elements = 2
  36.  
  37. def insert(x: String): Tree = {
  38. var order = x.compareTo(a)
  39. if (order < 0) return Tree(x, a, b)
  40. if (order == 0) return this
  41. order = x.compareTo(b)
  42. if (order < 0) return Tree(a, x, b)
  43. if (order == 0) return this
  44. return Tree(a, b, x)
  45. }
  46.  
  47. override def toString = "(" + a + " " + b + ")"
  48. }
  49.  
  50. case class Internal1(a: Tree, b: String, c: Tree) extends Tree {
  51. override def elements = 1
  52.  
  53. def insert(x: String): Tree = {
  54. val order = x.compareTo(b)
  55. if (order < 0) {
  56. val a_ = a.insert(x)
  57. if (a_.elements < a.elements) {
  58. val a__ = a_.asInstanceOf[Internal1]
  59. Internal2(a__.a, a__.b, a__.c, b, c)
  60. } else Internal1(a_, b, c)
  61. } else if (order > 0) {
  62. val c_ = c.insert(x)
  63. if (c_.elements < c.elements) {
  64. val c__ = c_.asInstanceOf[Internal1]
  65. Internal2(a, b, c__.a, c__.b, c__.c)
  66. } else Internal1(a, b, c_)
  67. }
  68.  
  69. override def toString = "(" + a.toString + " " + b + " " + c.toString + ")"
  70. }
  71.  
  72. case class Internal2(a: Tree, b: String, c: Tree, d: String, e: Tree) extends Tree {
  73. override def elements = 2
  74.  
  75. def insert(x: String): Tree = {
  76. var order = x.compareTo(b)
  77. if (order < 0) {
  78. val a_ = a.insert(x)
  79. if (a_.elements < a.elements) Internal1(a_, b, Internal1(c, d, e))
  80. else Internal2(a_, b, c, d, e)
  81. } else if (order > 0) {
  82. order = x.compareTo(d)
  83. if (order < 0) {
  84. val c_ = c.insert(x)
  85. if (c_.elements < c.elements) {
  86. val c__ = c_.asInstanceOf[Internal1]
  87. Internal1(Internal1(a, b, c__.a), c__.b, Internal1(c__.c, d, e))
  88. } else Internal2(a, b, c_, d, e)
  89. } else if (order > 0) {
  90. val e_ = e.insert(x)
  91. if (e_.elements < e.elements) Internal1(Internal1(a, b, c), d, e_)
  92. else Internal2(a, b, c, d, e_)
  93. }
  94.  
  95. override def toString = "(" + a.toString + " " + b + " " + c.toString + " " + d + " " + e.toString + ")"
  96. }
  97.  
  98. object Main {
  99. def main(args: Array[String]) {
  100. var a = Tree()
  101. println(a)
  102. for (x <- 'a' to 'z') {
  103. a = a.insert(x.toString)
  104. println(a)
  105. }
  106. }
  107. }
  108.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Usage: scalac <options> <source files>
where possible standard options include:
  -Dproperty=value                Pass -Dproperty=value directly to the runtime system.
  -J<flag>                        Pass <flag> directly to the runtime system.
  -P:<plugin>:<opt>               Pass an option to a plugin
  -X                              Print a synopsis of advanced options.
  -bootclasspath <path>           Override location of bootstrap class files.
  -classpath <path>               Specify where to find user class files.
  -d <directory|jar>              destination for generated classfiles.
  -dependencyfile <file>          Set dependency tracking file.
  -deprecation                    Emit warning and location for usages of deprecated APIs.
  -encoding <encoding>            Specify character encoding used by source files.
  -explaintypes                   Explain type errors in more detail.
  -extdirs <path>                 Override location of installed extensions.
  -feature                        Emit warning and location for usages of features that should be imported explicitly.
  -g:<level>                      Set level of generated debugging info. (none,source,line,vars,notailcalls) default:vars
  -help                           Print a synopsis of standard options
  -javabootclasspath <path>       Override java boot classpath.
  -javaextdirs <path>             Override java extdirs classpath.
  -language:<_,feature,-feature>  Enable or disable language features: `_' for all, `-language:help' to list
  -no-specialization              Ignore @specialize annotations.
  -nobootcp                       Do not use the boot classpath for the scala jars.
  -nowarn                         Generate no warnings.
  -optimise                       Generates faster bytecode by applying optimisations to the program
  -print                          Print program with Scala-specific features removed.
  -sourcepath <path>              Specify location(s) of source files.
  -target:<target>                Target platform for object files. All JVM 1.5 targets are deprecated. (jvm-1.5,jvm-1.6,jvm-1.7,jvm-1.8) default:jvm-1.6
  -toolcp <path>                  Add to the runner classpath.
  -unchecked                      Enable additional warnings where generated code depends on assumptions.
  -uniqid                         Uniquely tag all identifiers in debugging output.
  -usejavacp                      Utilize the java.class.path in classpath resolution.
  -usemanifestcp                  Utilize the manifest in classpath resolution.
  -verbose                        Output messages about what the compiler is doing.
  -version                        Print product version and exit.
  @<file>                         A text file containing compiler arguments (options and source files)

spoj: The program compiled successfully, but Main.class was not found.
      Class Main should contain method: def main(args: Array[String]).
stdout
Standard output is empty