Skip to content

Instantly share code, notes, and snippets.

@oludouglas
Last active September 15, 2020 12:57
Show Gist options
  • Save oludouglas/9acf4a51348fe57723bcafcd8118b39a to your computer and use it in GitHub Desktop.
Save oludouglas/9acf4a51348fe57723bcafcd8118b39a to your computer and use it in GitHub Desktop.
package interviews
import "testing"
type DoublyLinkedListNode struct {
value interface{}
prev *DoublyLinkedListNode
next *DoublyLinkedListNode
}
func (d *DoublyLinkedListNode) NextNode(node *DoublyLinkedListNode) {
d.next = node
}
func (d *DoublyLinkedListNode) PrevNode(node *DoublyLinkedListNode) {
d.prev = node
}
func TestDoublyLinkedList(t *testing.T) {
a := DoublyLinkedListNode{value: 3}
b := DoublyLinkedListNode{value: 3}
c := DoublyLinkedListNode{value: 3}
d := DoublyLinkedListNode{value: 3}
a.NextNode(&b)
b.NextNode(&c)
b.PrevNode(&a)
c.NextNode(&d)
c.PrevNode(&b)
if a.next != &b {
t.Errorf("Expected a %v but got %v", &b, a.next)
}
if a.value != 3 {
t.Errorf("Expected a %v but got %v", &b, a.next)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment