github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/structure/stacks/stacks.go (about)

     1  // Package stacks provides an abstract Stack interface.
     2  //
     3  // In computer science, a stack is an abstract data type that serves as a collection of elements, with two principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed. The order in which elements come off a stack gives rise to its alternative name, LIFO (for last in, first out). Additionally, a peek operation may give access to the top without modifying the stack.
     4  //
     5  // Reference: https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29
     6  package stacks
     7  
     8  import "github.com/songzhibin97/go-baseutils/structure/containers"
     9  
    10  // Stack interface that all stacks implement
    11  type Stack[E any] interface {
    12  	Push(value E)
    13  	Pop() (value E, ok bool)
    14  	Peek() (value E, ok bool)
    15  
    16  	containers.Container[E]
    17  	// Empty() bool
    18  	// Size() int
    19  	// Clear()
    20  	// Values() []E{}
    21  	// String() string
    22  }