1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 15:12:26 +08:00

refactor: change variable name to

This commit is contained in:
dudaodong
2022-07-18 15:52:51 +08:00
parent 1782b11ec4
commit 44370aef5e
13 changed files with 191 additions and 194 deletions

View File

@@ -208,13 +208,13 @@ func (link *DoublyLink[T]) Size() int {
// Values return slice of all doubly linklist node value
func (link *DoublyLink[T]) Values() []T {
res := []T{}
result := []T{}
current := link.Head
for current != nil {
res = append(res, current.Value)
result = append(result, current.Value)
current = current.Next
}
return res
return result
}
// Print all nodes info of a linked list

View File

@@ -213,13 +213,13 @@ func (link *SinglyLink[T]) Size() int {
// Values return slice of all singly linklist node value
func (link *SinglyLink[T]) Values() []T {
res := []T{}
result := []T{}
current := link.Head
for current != nil {
res = append(res, current.Value)
result = append(result, current.Value)
current = current.Next
}
return res
return result
}
// IsEmpty checks if link is empty or not

View File

@@ -222,24 +222,24 @@ func (l *List[T]) Unique() {
// Union creates a new list contain all element in list l and other, remove duplicate element.
func (l *List[T]) Union(other *List[T]) *List[T] {
res := NewList([]T{})
result := NewList([]T{})
res.data = append(res.data, l.data...)
res.data = append(res.data, other.data...)
res.Unique()
result.data = append(result.data, l.data...)
result.data = append(result.data, other.data...)
result.Unique()
return res
return result
}
// Intersection creates a new list whose element both be contained in list l and other
func (l *List[T]) Intersection(other *List[T]) *List[T] {
res := NewList(make([]T, 0, 0))
result := NewList(make([]T, 0, 0))
for _, v := range l.data {
if other.Contain(v) {
res.data = append(res.data, v)
result.data = append(result.data, v)
}
}
return res
return result
}

View File

@@ -84,20 +84,20 @@ func (t *BSTree[T]) HasSubTree(subTree *BSTree[T]) bool {
func hasSubTree[T any](superTreeRoot, subTreeRoot *datastructure.TreeNode[T],
comparator lancetconstraints.Comparator) bool {
res := false
result := false
if superTreeRoot != nil && subTreeRoot != nil {
if comparator.Compare(superTreeRoot.Value, subTreeRoot.Value) == 0 {
res = isSubTree(superTreeRoot, subTreeRoot, comparator)
result = isSubTree(superTreeRoot, subTreeRoot, comparator)
}
if !res {
res = hasSubTree(superTreeRoot.Left, subTreeRoot, comparator)
if !result {
result = hasSubTree(superTreeRoot.Left, subTreeRoot, comparator)
}
if !res {
res = hasSubTree(superTreeRoot.Right, subTreeRoot, comparator)
if !result {
result = hasSubTree(superTreeRoot.Right, subTreeRoot, comparator)
}
}
return res
return result
}
// Print the bstree structure

View File

@@ -226,8 +226,8 @@ func isSubTree[T any](superTreeRoot, subTreeRoot *datastructure.TreeNode[T], com
if comparator.Compare(superTreeRoot.Value, subTreeRoot.Value) != 0 {
return false
}
res := isSubTree(superTreeRoot.Left, subTreeRoot.Left, comparator) && isSubTree(superTreeRoot.Right, subTreeRoot.Right, comparator)
return res
result := isSubTree(superTreeRoot.Left, subTreeRoot.Left, comparator) && isSubTree(superTreeRoot.Right, subTreeRoot.Right, comparator)
return result
}
func max(a, b int) int {