Я использую Scala 2.11 и Scala IDE. И у меня есть следующая проблема: У меня есть 2 файла с реализацией fo Weight Biased Leftist Heap и драйвер, который является объектом, с его основным методом.не найдено: Введите основной метод scala
WBLHeap.scala
package heaps
abstract class WBLHeap[+A] {
/**
* O(1)
* @return weight of the heap
*/
def weight() : Int
/**
*
*/
def isWeightedLeftist(): Boolean
/**
* For any WBLT with n elements, the length of its right spine
* is <= floor(log2(n+1))
*/
def rightSpine() : List[A]
/**
* O(log(n))
* @return A WBLHeap with the heap this and the heap h
*/
def merge[B >: A](h: WBLHeap[B]) : WBLHeap[B]
case object EmptyHeap extends WBLHeap[Nothing] {
def weight(): Int = 0
def isWeightedLeftist(): Boolean = true
def rightSpine() : List[Nothing] = List()
def merge[B >: Nothing](h: WBLHeap[B]) : WBLHeap[B] = h
}
case class Node[A](elem: A, weightNode: Int, left: WBLHeap[A], right: WBLHeap[A]) extends WBLHeap[A] {
def weight(): Int = weightNode
def isWeightedLeftist(): Boolean =
left.weight >= right.weight && left.isWeightedLeftist() &&
right.isWeightedLeftist()
def rightSpine() : List[A] = elem :: right.rightSpine()
def merge[B >: A](h: WBLHeap[B]) : WBLHeap[B] = h match {
case EmptyHeap => this
case Node(e, w, l: WBLHeap[B], r: WBLHeap[B]) if this.weightNode <= w => buildNode(elem, left, r.merge(h))
case Node(e: B, w, l: WBLHeap[B], r: WBLHeap[B]) if this.weightNode > w => buildNode(e, l, this.merge(r))
//There is a warning here but I don't know why.
//abstract type pattern A is unchecked since it is eliminated by erasure
}
private def buildNode[B >: A](x: B, h1: WBLHeap[B], h2: WBLHeap[B]): WBLHeap[B] = {
val w1 = h1.weight()
val w2 = h2.weight()
val newWeight = w1 + w2 + 1
if(w1 >= w2)
return new Node[B](x, newWeight, h1, h2)
else
return new Node[B](x, newWeight, h2, h1)
}
}
}
Driver.scala
package heaps
object Driver {
def main(args:Array[String]) = {
val h = new Node[Char]('b', 2,
new Node[Char]('c', 1, EmptyHeap(), EmptyHeap()),
EmptyHeap())
}
}
В строке: "VAL ч = новый узел [Char] ('B', 2", у меня есть ошибка : не найден:..? тип узла Это также происходит каждый раз я использую объект EmptyHeap
кто-нибудь знает, что я делаю неправильно
Спасибо!
Кроме того, вы должны удалить() после вызовов EmptyHeap. –