diff --git a/stacks/linkedliststack/linkedliststack.go b/stacks/linkedliststack/linkedliststack.go index 00cdc89..41650fa 100644 --- a/stacks/linkedliststack/linkedliststack.go +++ b/stacks/linkedliststack/linkedliststack.go @@ -25,6 +25,7 @@ package linkedliststack import ( "fmt" + "strings" ) type Stack struct { @@ -68,10 +69,12 @@ func (stack *Stack) Peek() (value interface{}, ok bool) { return nil, false } +// Returns true if stack does not contain any elements. func (stack *Stack) Empty() bool { return stack.size == 0 } +// Returns number of elements within the stack. func (stack *Stack) Size() int { return stack.size } @@ -81,12 +84,12 @@ func (stack *Stack) String() string { element := stack.top elementsValues := []string{} for element != nil { - elementsValues = append(elementsValues, fmt.Sprintf("%v ", element.value)) + elementsValues = append(elementsValues, fmt.Sprintf("%v", element.value)) element = element.next } for i, j := 0, len(elementsValues)-1; i < j; i, j = i+1, j-1 { elementsValues[i], elementsValues[j] = elementsValues[j], elementsValues[i] } - str += fmt.Sprintf("#v", elementsValues) + str += strings.Join(elementsValues, ", ") return str } diff --git a/stacks/linkedliststack/linkedliststack_test.go b/stacks/linkedliststack/linkedliststack_test.go index 9503736..6e7f115 100644 --- a/stacks/linkedliststack/linkedliststack_test.go +++ b/stacks/linkedliststack/linkedliststack_test.go @@ -19,6 +19,7 @@ with this distribution for more information. package linkedliststack import ( + "fmt" "testing" ) @@ -35,6 +36,8 @@ func TestLinkedListStack(t *testing.T) { stack.Push(2) stack.Push(3) + fmt.Println(stack) + if actualValue := stack.Empty(); actualValue != false { t.Errorf("Got %v expected %v", actualValue, false) }