当前位置: 首页>>代码示例>>Golang>>正文


Golang algorithms.Comparable类代码示例

本文整理汇总了Golang中algorithms.Comparable的典型用法代码示例。如果您正苦于以下问题:Golang Comparable类的具体用法?Golang Comparable怎么用?Golang Comparable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Comparable类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: _delete

func (this *BinarySearchTree) _delete(x *Node, key algorithms.Comparable) *Node {
	if x == nil {
		return nil
	}
	cmp := key.CompareTo(x.key)
	if cmp < 0 {
		x.left = this._delete(x.left, key)
	} else if cmp > 0 {
		x.right = this._delete(x.right, key)
	} else {
		if x.right == nil {
			return x.left
		}
		if x.left == nil {
			return x.right
		}
		t := x
		x = this.min(t.right)
		x.right = this.deleteMin(t.right)
		x.left = t.left
	}

	x.size = this.size(x.left) + this.size(x.right) + 1

	return x
}
开发者ID:hinike,项目名称:algorithms,代码行数:26,代码来源:BinarySearchTree.go

示例2: RangedSize

func (this *BinarySearchTree) RangedSize(low, high algorithms.Comparable) int {
	if high.CompareTo(low) < 0 {
		return 0
	} else if this.Contains(high) {
		return this.Rank(high) - this.Rank(low) + 1
	} else {
		return this.Rank(high) - this.Rank(low)
	}
}
开发者ID:hinike,项目名称:algorithms,代码行数:9,代码来源:BinarySearchTree.go

示例3: get

func (this *BinarySearchTree) get(x *Node, key algorithms.Comparable) interface{} {
	if x == nil {
		return nil
	}

	cmp := key.CompareTo(x.key)
	if cmp < 0 {
		return this.get(x.left, key)
	} else if cmp > 0 {
		return this.get(x.right, key)
	} else {
		return x.val
	}
}
开发者ID:hinike,项目名称:algorithms,代码行数:14,代码来源:BinarySearchTree.go

示例4: rank

func (this *BinarySearchTree) rank(x *Node, key algorithms.Comparable) int {
	if x == nil {
		return 0
	}

	cmp := key.CompareTo(x.key)
	if cmp < 0 {
		return this.rank(x.left, key)
	} else if cmp > 0 {
		return this.rank(x.right, key) + this.size(x.left) + 1
	} else {
		return this.size(x.left)
	}
}
开发者ID:hinike,项目名称:algorithms,代码行数:14,代码来源:BinarySearchTree.go

示例5: keys

func (this *BinarySearchTree) keys(x *Node, queue *container.Queue, low, high algorithms.Comparable) {
	if x == nil {
		return
	}
	cmplow := low.CompareTo(x.key)
	cmphigh := high.CompareTo(x.key)
	if cmplow < 0 {
		this.keys(x.left, queue, low, high)
	}
	if cmplow <= 0 && cmphigh >= 0 {
		queue.Push(x.key)
	}
	if cmphigh > 0 {
		this.keys(x.right, queue, low, high)
	}
}
开发者ID:hinike,项目名称:algorithms,代码行数:16,代码来源:BinarySearchTree.go

示例6: set

func (this *BinarySearchTree) set(x *Node, key algorithms.Comparable, val interface{}) *Node {
	if x == nil {
		return NewNode(key, val, 1)
	}

	cmp := key.CompareTo(x.key)
	if cmp < 0 {
		x.left = this.set(x.left, key, val)
	} else if cmp > 0 {
		x.right = this.set(x.right, key, val)
	} else {
		x.val = val
	}

	x.size = this.size(x.left) + this.size(x.right) + 1

	return x
}
开发者ID:hinike,项目名称:algorithms,代码行数:18,代码来源:BinarySearchTree.go

示例7: ceil

func (this *BinarySearchTree) ceil(x *Node, key algorithms.Comparable) *Node {
	if x == nil {
		return nil
	}

	cmp := key.CompareTo(x.key)
	if cmp == 0 {
		return x
	} else if cmp > 0 {
		return this.ceil(x.right, key)
	} else {
		t := this.ceil(x.left, key)
		if t != nil {
			return t
		} else {
			return x
		}
	}
}
开发者ID:hinike,项目名称:algorithms,代码行数:19,代码来源:BinarySearchTree.go

示例8: Less

func (this *sorter) Less(v, w algorithms.Comparable) bool {
	return v.CompareTo(w) < 0
}
开发者ID:hinike,项目名称:algorithms,代码行数:3,代码来源:Sorter.go


注:本文中的algorithms.Comparable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。