add Clear() method to stack interface

pull/1/head
Emir Pasic 9 years ago
parent 6a23043927
commit ce767c333d

@ -88,6 +88,12 @@ func (stack *Stack) Size() int {
return stack.top + 1
}
// Removes all elements from the stack.
func (stack *Stack) Clear() {
stack.top = -1
stack.items = []interface{}{}
}
func (stack *Stack) String() string {
str := "ArrayStack\n"
values := []string{}

@ -84,6 +84,12 @@ func (stack *Stack) Size() int {
return stack.size
}
// Removes all elements from the stack.
func (stack *Stack) Clear() {
stack.top = nil
stack.size = 0
}
func (stack *Stack) String() string {
str := "LinkedListStack\n"
element := stack.top

@ -24,4 +24,5 @@ type Interface interface {
Peek() (value interface{}, ok bool)
Empty() bool
Size() int
Clear()
}

Loading…
Cancel
Save