TODO: assertImplementation, add interface InsertIf 组合等
This commit is contained in:
@@ -78,10 +78,10 @@ func (iter *CircularIterator) Next() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (iter *CircularIterator) MoveToHead() {
|
||||
func (iter *CircularIterator) ToHead() {
|
||||
iter.cur = iter.pl.head
|
||||
}
|
||||
|
||||
func (iter *CircularIterator) MoveToTail() {
|
||||
func (iter *CircularIterator) ToTail() {
|
||||
iter.cur = iter.pl.tail
|
||||
}
|
||||
|
||||
@@ -57,6 +57,21 @@ func (l *LinkedList) Size() uint {
|
||||
return l.size
|
||||
}
|
||||
|
||||
func (l *LinkedList) Push(value interface{}) {
|
||||
var node *Node
|
||||
l.size++
|
||||
|
||||
node = &Node{}
|
||||
node.value = value
|
||||
|
||||
tprev := l.tail.prev
|
||||
tprev.next = node
|
||||
|
||||
node.prev = tprev
|
||||
node.next = l.tail
|
||||
l.tail.prev = node
|
||||
}
|
||||
|
||||
func (l *LinkedList) PushFront(values ...interface{}) {
|
||||
|
||||
var node *Node
|
||||
|
||||
@@ -7,6 +7,24 @@ import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func TestPush(t *testing.T) {
|
||||
l := New()
|
||||
for i := 0; i < 5; i++ {
|
||||
l.Push(i)
|
||||
}
|
||||
var result string
|
||||
result = spew.Sprint(l.Values())
|
||||
if result != "[0 1 2 3 4]" {
|
||||
t.Error(result)
|
||||
}
|
||||
|
||||
l.Push(0)
|
||||
result = spew.Sprint(l.Values())
|
||||
if result != "[0 1 2 3 4 0]" {
|
||||
t.Error(result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPushFront(t *testing.T) {
|
||||
l := New()
|
||||
for i := 0; i < 5; i++ {
|
||||
@@ -602,7 +620,7 @@ func TestCircularIterator(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
iter.MoveToTail()
|
||||
iter.ToTail()
|
||||
for i := 0; i != 10; i++ {
|
||||
iter.Prev()
|
||||
if iter.Value() != i {
|
||||
|
||||
Reference in New Issue
Block a user