當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。