forked from root/public
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
2.5 KiB
88 lines
2.5 KiB
![]()
4 years ago
|
package main
|
||
![]()
4 years ago
|
|
||
|
import (
|
||
![]()
4 years ago
|
"fmt"
|
||
|
|
||
![]()
4 years ago
|
student "student"
|
||
|
|
||
![]()
4 years ago
|
"./correct"
|
||
![]()
4 years ago
|
"github.com/01-edu/public/go/lib"
|
||
![]()
4 years ago
|
)
|
||
|
|
||
![]()
4 years ago
|
func errorMessage_search(fn interface{}, root, a *correct.TreeNode, b *student.TreeNode,
|
||
![]()
4 years ago
|
seaVal string) {
|
||
![]()
4 years ago
|
lib.Fatalf("%s(\n%s\n, %s) == %s instead of %s\n",
|
||
![]()
4 years ago
|
"BTreeSearchItem",
|
||
![]()
4 years ago
|
correct.FormatTree(root),
|
||
![]()
4 years ago
|
seaVal,
|
||
|
b.Data,
|
||
|
a.Data,
|
||
|
)
|
||
|
}
|
||
|
|
||
![]()
4 years ago
|
func CompareNode_search(fn interface{}, arg1, a *correct.TreeNode, b *student.TreeNode,
|
||
![]()
4 years ago
|
seaVal string) {
|
||
|
if a == nil && b == nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if (a == nil && b != nil) || (b == nil && a != nil) {
|
||
![]()
4 years ago
|
lib.Fatalf("Expected %v instead of %v\n", a, b)
|
||
![]()
4 years ago
|
return
|
||
|
}
|
||
|
|
||
|
if a.Data != b.Data {
|
||
![]()
4 years ago
|
errorMessage_search(fn, arg1, a, b, seaVal)
|
||
![]()
4 years ago
|
}
|
||
|
|
||
|
if a.Parent != nil && b.Parent != nil {
|
||
|
if a.Parent.Data != b.Parent.Data {
|
||
![]()
4 years ago
|
errorMessage_search(fn, arg1, a, b, seaVal)
|
||
![]()
4 years ago
|
lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent.Data, b.Parent.Data)
|
||
![]()
4 years ago
|
fmt.Println("Parent.Data", a.Parent.Data, b.Parent.Data)
|
||
|
}
|
||
|
} else if (a.Parent == nil && b.Parent != nil) || (a.Parent != nil && b.Parent == nil) {
|
||
![]()
4 years ago
|
lib.Fatalf("Expected parent value %v instead of %v\n", a.Parent, b.Parent)
|
||
![]()
4 years ago
|
}
|
||
|
|
||
|
if a.Right != nil && b.Right != nil {
|
||
|
if a.Right.Data != b.Right.Data {
|
||
![]()
4 years ago
|
errorMessage_search(fn, arg1, a, b, seaVal)
|
||
![]()
4 years ago
|
lib.Fatalf("Expected right child value %v instead of %v\n", a.Right.Data, b.Right.Data)
|
||
![]()
4 years ago
|
fmt.Println("Right.Data", a.Right.Data, b.Right.Data)
|
||
|
}
|
||
|
} else if (a.Right == nil && b.Right != nil) || (a.Right != nil && b.Right == nil) {
|
||
![]()
4 years ago
|
lib.Fatalf("Expected right child value %v instead of %v\n", a.Right, b.Right)
|
||
![]()
4 years ago
|
}
|
||
|
|
||
|
if a.Left != nil && b.Left != nil {
|
||
|
if a.Left.Data != b.Left.Data {
|
||
![]()
4 years ago
|
errorMessage_search(fn, arg1, a, b, seaVal)
|
||
![]()
4 years ago
|
lib.Fatalf("Expected left child value %v instead of %v\n", a.Left, b.Left)
|
||
![]()
4 years ago
|
fmt.Println("Left.Data", a.Left.Data, b.Left.Data)
|
||
|
}
|
||
|
} else if (a.Left == nil && b.Left != nil) || (a.Left != nil && b.Left == nil) {
|
||
![]()
4 years ago
|
lib.Fatalf("Expected left child value %v instead of %v\n", a, b)
|
||
![]()
4 years ago
|
}
|
||
|
}
|
||
|
|
||
![]()
4 years ago
|
func main() {
|
||
![]()
4 years ago
|
root := &correct.TreeNode{Data: "04"}
|
||
![]()
4 years ago
|
rootS := &student.TreeNode{Data: "04"}
|
||
|
|
||
|
ins := []string{"01", "07", "05", "12", "02", "03", "10"}
|
||
|
|
||
|
for _, v := range ins {
|
||
![]()
4 years ago
|
root = correct.BTreeInsertData(root, v)
|
||
![]()
4 years ago
|
rootS = student.BTreeInsertData(rootS, v)
|
||
|
}
|
||
![]()
4 years ago
|
fn := interface{}(correct.BTreeSearchItem)
|
||
![]()
4 years ago
|
|
||
|
ins = append(ins, "322")
|
||
|
for _, v := range ins {
|
||
![]()
4 years ago
|
selectedSol := correct.BTreeSearchItem(root, v)
|
||
![]()
4 years ago
|
selectedStu := student.BTreeSearchItem(rootS, v)
|
||
![]()
4 years ago
|
CompareNode_search(fn, root, selectedSol, selectedStu, v)
|
||
![]()
4 years ago
|
}
|
||
|
}
|