From f8635b5cf2d6ecc9ee6d143ed9b40f4a7a7f7813 Mon Sep 17 00:00:00 2001 From: milarin Date: Fri, 20 Jan 2023 22:12:17 +0100 Subject: [PATCH] added Clear() method for stacks and queues --- impl_queue_list.go | 4 ++++ impl_stack_list.go | 4 ++++ int_queue.go | 1 + int_stack.go | 1 + 4 files changed, 10 insertions(+) diff --git a/impl_queue_list.go b/impl_queue_list.go index 2b181d8..9e74c19 100644 --- a/impl_queue_list.go +++ b/impl_queue_list.go @@ -41,3 +41,7 @@ func (s *ListQueue[T]) Size() int { func (s *ListQueue[T]) Empty() bool { return s.Size() == 0 } + +func (s *ListQueue[T]) Clear() { + s.list.Clear() +} diff --git a/impl_stack_list.go b/impl_stack_list.go index 9a59f4b..09fa46d 100644 --- a/impl_stack_list.go +++ b/impl_stack_list.go @@ -41,3 +41,7 @@ func (s *ListStack[T]) Size() int { func (s *ListStack[T]) Empty() bool { return s.Size() == 0 } + +func (s *ListStack[T]) Clear() { + s.list.Clear() +} diff --git a/int_queue.go b/int_queue.go index 921e02a..ff0f8c8 100644 --- a/int_queue.go +++ b/int_queue.go @@ -3,6 +3,7 @@ package ds type Queue[T any] interface { Addable[T] Sized + Clearable Enqueue(value T) Dequeue() T diff --git a/int_stack.go b/int_stack.go index 86afb80..cb48048 100644 --- a/int_stack.go +++ b/int_stack.go @@ -3,6 +3,7 @@ package ds type Stack[T any] interface { Addable[T] Sized + Clearable Push(value T) Pop() T