本文整理汇总了Golang中ctci/datastructures.LinkedList.SetTail方法的典型用法代码示例。如果您正苦于以下问题:Golang LinkedList.SetTail方法的具体用法?Golang LinkedList.SetTail怎么用?Golang LinkedList.SetTail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctci/datastructures.LinkedList
的用法示例。
在下文中一共展示了LinkedList.SetTail方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Slice
// Gives sliced linked list from kth element to last element.
// Also it assumes that, we don't know size&last element of the linkedlist.
func Slice(l datastructures.LinkedList, kth int) *datastructures.LinkedList {
if kth <= 0 {
return nil
}
current := l.Head()
runner := current
sliced_list := datastructures.LinkedList{}
count := 0
for current != nil {
runner = current
if count == kth {
sliced_list.SetHead(current)
for runner != nil {
runner = runner.Next()
}
break
sliced_list.SetTail(current)
}
count++
current = current.Next()
}
if sliced_list.Head() != nil {
return &sliced_list
} else {
return nil
}
}
示例2: PartitionList
// partition given list into two parts due to the given value
// and then merge them together.
func PartitionList(l datastructures.LinkedList, value int) datastructures.LinkedList {
beforeValue := datastructures.LinkedList{}
afterValue := datastructures.LinkedList{}
head := l.Head()
for head != nil {
n := datastructures.Node{}
n.SetValue(head.GetValue())
if head.GetValue() < value {
beforeValue.Add(&n)
} else {
afterValue.Add(&n)
}
head = head.Next()
}
beforeValue.SetTail(afterValue.Head())
return beforeValue
}