Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
pp:2025:scala:l05 [2025/03/31 17:49] ldaniel |
pp:2025:scala:l05 [2025/04/04 15:09] (current) tpruteanu |
||
---|---|---|---|
Line 80: | Line 80: | ||
val alignedX = " " * (ncenter - (strValue.length / 2) - 1) + strValue | val alignedX = " " * (ncenter - (strValue.length / 2) - 1) + strValue | ||
val centerLine = " " * (ncenter - 1) + "|" | val centerLine = " " * (ncenter - 1) + "|" | ||
- | val dottedLine = " " * (ppL.center - 1) + "-" * (nlen - ppL.center - ppR.center + 2) | + | val dottedLine = " " * (ppL.center - 1) + "-" * (nlen - ppL.center - (ppR.len - ppR.center + 1) + 2) |
- | val downLines = " " * (ppL.center - 1) + "|" + " " * (nlen - ppL.center - ppR.center) + "|" | + | val downLines = " " * (ppL.center - 1) + "|" + " " * (nlen - ppL.center - (ppR.len - ppR.center +1)) + "|" |
val combinedLines = zipPad("",(l, r) => l ++ (" " * (ppL.len - l.size + 1 )) ++ r, ppL.text, ppR.text) | val combinedLines = zipPad("",(l, r) => l ++ (" " * (ppL.len - l.size + 1 )) ++ r, ppL.text, ppR.text) | ||
+ | | ||
PrintInfo(nlen, ncenter, alignedX :: centerLine :: dottedLine :: downLines :: combinedLines) | PrintInfo(nlen, ncenter, alignedX :: centerLine :: dottedLine :: downLines :: combinedLines) | ||
} | } | ||
Line 90: | Line 90: | ||
case (Nil, Nil) => Nil | case (Nil, Nil) => Nil | ||
case (x :: xs, Nil) => x :: zipPad(pad, f, xs, List(pad)) | case (x :: xs, Nil) => x :: zipPad(pad, f, xs, List(pad)) | ||
- | case (Nil, y :: ys) => y :: zipPad(pad, f, List(pad), ys) | + | case (Nil, y :: ys) => f(pad, y) :: zipPad(pad, f, List(pad), ys) |
case (x :: xs, y :: ys) => f(x, y) :: zipPad(pad, f, xs, ys) | case (x :: xs, y :: ys) => f(x, y) :: zipPad(pad, f, xs, ys) | ||
} | } | ||
Line 96: | Line 96: | ||
def printTree(tree: BTree): String = "\n" + pp(tree).text.mkString("\n") | def printTree(tree: BTree): String = "\n" + pp(tree).text.mkString("\n") | ||
} | } | ||
+ | |||
extension(t: BTree) { | extension(t: BTree) { | ||
def toStringTree: String = BTreePrinter.printTree(t) | def toStringTree: String = BTreePrinter.printTree(t) |