Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sealed trait BT[+A,+B]
- case class Node[+A,+B] (value:(A,B),right:List[BT[A,B]]) extends BT[A,B]
- val a=Node(("Wrocław",20.0),List())
- val b=Node(("Warszawa",10.0),List())
- val c=Node(("Poznań",5.0),List(a))
- val d=Node(("Gdańsk",7.0),List(b))
- val graf = Node(("Kraków",0.0),List(c,d))
- /*toooooooo nie działa od tego momemntu w dół*/
- def mediumRoad(g:Node[String,Double]): Double ={
- def road(visited: List[BT[String,Double]])(toVisit: List[BT[String,Double]])(suma:Double): Double =toVisit match{
- case Nil => suma/visited.length
- case h::t=>{
- val Node((nazwa,odleglosc),lista)=h
- if (visited contains h) road(visited)(t)(suma)
- else road(h::visited)(t ++ lista)(suma+
- lista.foldLeft(0)((acc,Node((a,miasto),b)=>acc+Math.abs(odleglosc-miasto)
- )
- }
- }
- road(Nil)(List(g))(0)
- }
- mediumRoad (graf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement