1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 07:02:29 +08:00

feat: add stackarray.go implements stack with array

This commit is contained in:
dudaodong
2022-02-04 19:35:06 +08:00
parent 10ed71a3a2
commit eb59d02a08
3 changed files with 151 additions and 1 deletions

View File

@@ -1,13 +1,24 @@
package datastructure
// LinkNode is a linkedlist node, which have a value and Pre points to previous node, Next points to a next node of the link.
// LinkNode is a linkedlist node, which have a Value and Pre points to previous node, Next points to a next node of the link.
type LinkNode[T any] struct {
Value T
Pre *LinkNode[T]
Next *LinkNode[T]
}
// NewLinkNode return a LinkNode pointer
func NewLinkNode[T any](value T) *LinkNode[T] {
return &LinkNode[T]{value, nil, nil}
}
// StackNode is a node in stack, which have a Value and Pre points to previous node in the stack.
type StackNode[T any] struct {
Value T
Pre *StackNode[T]
}
// NewStackNode return a StackNode pointer
func NewStackNode[T any](value T) *StackNode[T] {
return &StackNode[T]{value, nil}
}