From 957e6356f640854b56b240be7776e18a4adecd23 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Wed, 26 Jan 2022 15:25:02 +0800 Subject: [PATCH] feat: add singlelink --- datastructure/singlylink.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 datastructure/singlylink.go diff --git a/datastructure/singlylink.go b/datastructure/singlylink.go new file mode 100644 index 0000000..c06cc79 --- /dev/null +++ b/datastructure/singlylink.go @@ -0,0 +1,12 @@ +package datastructure + +// Node is a linkedlist node, which have a value and Pre points to previous node, Next points to a next node of the link. +type Node[T any] struct { + Value T + Pre *Node[T] + Next *Node[T] +} + +func NewNode[T any](value T) *Node[T] { + return &Node[T]{value, nil, nil} +}