2 Star 1 Fork 0

简单 / gostl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
op.go 644 Bytes
一键复制 编辑 原始数据 按行查看 历史
简单 提交于 2023-01-03 19:01 . jhl
package algorithm
import (
"gitee.com/jianhaolin/gostl/utils/iterator"
)
// Swap swaps the value of two iterator
func Swap[T any](a, b iterator.Iterator[T]) {
va := a.Value()
vb := b.Value()
a.SetValue(vb)
b.SetValue(va)
}
// Reverse reverse the elements in the range [first, last]
func Reverse[T any](first, last iterator.BidIterator[T]) {
left := first.Clone().(iterator.BidIterator[T])
right := last.Clone().(iterator.BidIterator[T]).Prev().(iterator.BidIterator[T])
for !left.Equal(right) {
Swap(left.(iterator.Iterator[T]), right.(iterator.Iterator[T]))
left.Next()
if left.Equal(right) {
break
}
right.Prev()
}
}
Go
1
https://gitee.com/jianhaolin/gostl.git
git@gitee.com:jianhaolin/gostl.git
jianhaolin
gostl
gostl
v1.3.27

搜索帮助

53164aa7 5694891 3bd8fe86 5694891