added Clear() method for stacks and queues

This commit is contained in:
milarin 2023-01-20 22:12:17 +01:00
parent a83a8ca68e
commit f8635b5cf2
4 changed files with 10 additions and 0 deletions

View File

@ -41,3 +41,7 @@ func (s *ListQueue[T]) Size() int {
func (s *ListQueue[T]) Empty() bool { func (s *ListQueue[T]) Empty() bool {
return s.Size() == 0 return s.Size() == 0
} }
func (s *ListQueue[T]) Clear() {
s.list.Clear()
}

View File

@ -41,3 +41,7 @@ func (s *ListStack[T]) Size() int {
func (s *ListStack[T]) Empty() bool { func (s *ListStack[T]) Empty() bool {
return s.Size() == 0 return s.Size() == 0
} }
func (s *ListStack[T]) Clear() {
s.list.Clear()
}

View File

@ -3,6 +3,7 @@ package ds
type Queue[T any] interface { type Queue[T any] interface {
Addable[T] Addable[T]
Sized Sized
Clearable
Enqueue(value T) Enqueue(value T)
Dequeue() T Dequeue() T

View File

@ -3,6 +3,7 @@ package ds
type Stack[T any] interface { type Stack[T any] interface {
Addable[T] Addable[T]
Sized Sized
Clearable
Push(value T) Push(value T)
Pop() T Pop() T