Ex_GoAlgorithms/doublyLinkedList.go
2024-05-30 11:50:30 +04:00

37 lines
503 B
Go

package main
import "fmt"
type Node struct {
value int
next *Node
prev *Node
}
type DoublyLinkedList struct {
head *Node
tail *Node
}
func (list *DoublyLinkedList) addNode(value int) {
node := &Node{value: value}
if list.head == nil {
list.head = node
list.tail = node
} else {
node.prev = list.tail
list.tail.next = node
list.tail = node
}
}
func (list *DoublyLinkedList) printList() {
node := list.head
for node != nil {
fmt.Println(node.value)
node = node.next
}
}