-
Notifications
You must be signed in to change notification settings - Fork 0
/
stacker.go
36 lines (27 loc) · 950 Bytes
/
stacker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package stack
type Stacker[T any] interface {
/* Sets the equality comparer to the given function */
SetEqualityComparer(equals func(*T, *T) bool)
/* Returns the size of the stack */
Size() int
/* Returns true if the stack is empty. Otherwise, false */
Empty() bool
/* Pushes the given value to the stack */
Push(element T)
/* Removes the element to the stack. Panics if the stack is empty */
Pop()
/*
Returns a reference to the recently pushed element in the stack without removing it. Panics if stack is
empty
*/
Peek() *T
/* Returns true if the given value is found in the stack. Otherwise, false */
Contains(element T) bool
/* Empties the stack. Operations performed depends on the implementation */
Clear()
/*
Iterates through each element in the stack and executes the given function. Note that the order of
iteration will be the opposite of the order each element would be popped
*/
ForEach(do func(*T))
}