Fix stack algo
continuous-integration/drone/push Build is failing Details

main
Андрей Иванов 2024-09-26 18:55:27 +03:00
parent 685eeec2aa
commit 5fa2cd8bb3
2 changed files with 10 additions and 10 deletions

View File

@ -85,26 +85,26 @@ func (root *Node) WeightingTreeWithDLL(parent *Node) map[string]*WeightedNode {
weight: weight, weight: weight,
}} }}
dllist := dll.NewList() dllist := dll.NewList()
dllist.PushFront(root) dllist.PushFront(*root)
for dllist.Len() > 0 { for dllist.Len() > 0 {
current := dllist.Front() current := dllist.Front()
dllist.Remove(current) dllist.Remove(current)
nodeWeight := current.Value.(*Node).getNodeWeight() nodeWeight := current.Value.(*Node).getNodeWeight()
counter[current.Value.(Node).ID].weight = nodeWeight counter[current.Value.(*Node).ID].weight = nodeWeight
// Прибавляем вес всем родительским нодам до корня // Прибавляем вес всем родительским нодам до корня
parentNode := counter[current.Value.(Node).ID].parent parentNode := counter[current.Value.(*Node).ID].parent
for { for {
currentNode := counter[parentNode.ID]
if parentNode == nil { if parentNode == nil {
break break
} }
currentNode := counter[parentNode.ID]
currentNode.weight = currentNode.weight + nodeWeight currentNode.weight = currentNode.weight + nodeWeight
parentNode = currentNode.parent parentNode = currentNode.parent
} }
for _, child := range current.Value.(Node).Children { for _, child := range current.Value.(*Node).Children {
counter[child.ID] = &WeightedNode{ counter[child.ID] = &WeightedNode{
parent: current.Value.(*Node), parent: current.Value.(*Node),
} }

View File

@ -24,11 +24,11 @@ func TestNode_WeighingTreeAllAlgo(t *testing.T) {
printExpectations(tt.Weights, weightTreeWithStack) printExpectations(tt.Weights, weightTreeWithStack)
assert.EqualValues(t, tt.Weights, weightTreeWithStack) assert.EqualValues(t, tt.Weights, weightTreeWithStack)
}) })
//t.Run("WeightingTreeWithDLL", func(t *testing.T) { t.Run("WeightingTreeWithDLL", func(t *testing.T) {
// weightTreeWithDLL := tt.Tree.WeightingTreeWithDLL(nil) weightTreeWithDLL := tt.Tree.WeightingTreeWithDLL(nil)
// printExpectations(tt.Weights, weightTreeWithDLL) printExpectations(tt.Weights, weightTreeWithDLL)
// assert.EqualValues(t, tt.Weights, weightTreeWithDLL) assert.EqualValues(t, tt.Weights, weightTreeWithDLL)
//}) })
}) })
} }
} }