From 307fadc6e2cd0f8540580df1cbb7d5fde5074691 Mon Sep 17 00:00:00 2001 From: Alexander Kuleshov Date: Mon, 20 Feb 2017 17:18:03 +0600 Subject: [PATCH] go fmt for stack --- stack/stack.go | 72 ++++++++++++++++++++++----------------------- stack/stack_test.go | 32 ++++++++++---------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/stack/stack.go b/stack/stack.go index 1c7b22d..cc878fe 100644 --- a/stack/stack.go +++ b/stack/stack.go @@ -1,61 +1,61 @@ package stack type Stack struct { - st []interface{} - len int + st []interface{} + len int } func New() *Stack { - stack := &Stack{} - stack.st = make([]interface{}, 1) - stack.len = 0 - return stack + stack := &Stack{} + stack.st = make([]interface{}, 1) + stack.len = 0 + return stack } func (stack *Stack) Length() int { - return stack.len + return stack.len } func (stack *Stack) Pop() { - stack.st = stack.st[1:] - stack.len -= 1 + stack.st = stack.st[1:] + stack.len -= 1 } func (stack *Stack) Peek() interface{} { - return stack.st[0] + return stack.st[0] } func (stack *Stack) IsEmpty() bool { - return (stack.len == 0) + return (stack.len == 0) } func (stack *Stack) Push(value interface{}) { - add(stack, value) -} + add(stack, value) +} func add(slice *Stack, value interface{}) { - slice.len += 1 - var tmpSlice []interface{} = make([]interface{}, slice.len) - if slice.len == 0 { - slice.st[0] = value - return - } - - for i:=0; i < slice.len; i++ { - tmpSlice[i] = 0 - } - - for i:=0; i < slice.len; i++ { - if i == 0 { - tmpSlice[0] = value - } else { - tmpSlice[i] = slice.st[i - 1] - } + slice.len += 1 + var tmpSlice []interface{} = make([]interface{}, slice.len) + if slice.len == 0 { + slice.st[0] = value + return + } - if i == slice.len - 1 { - break - } - } - - slice.st = tmpSlice + for i := 0; i < slice.len; i++ { + tmpSlice[i] = 0 + } + + for i := 0; i < slice.len; i++ { + if i == 0 { + tmpSlice[0] = value + } else { + tmpSlice[i] = slice.st[i-1] + } + + if i == slice.len-1 { + break + } + } + + slice.st = tmpSlice } diff --git a/stack/stack_test.go b/stack/stack_test.go index f5c87fd..eee4749 100644 --- a/stack/stack_test.go +++ b/stack/stack_test.go @@ -3,23 +3,23 @@ package stack import "testing" func Test_Stack(t *testing.T) { - stack := New() + stack := New() - stack.Push(5) - stack.Push(6) - stack.Push(7) - - if stack.Length() != 3 { - t.Error("[Error] stack length is wrong") - } + stack.Push(5) + stack.Push(6) + stack.Push(7) - stack.Pop() + if stack.Length() != 3 { + t.Error("[Error] stack length is wrong") + } - if stack.Length() != 2 { - t.Error("[Error] stack length is wrong after pop") - } - - if stack.Peek() != 6 { - t.Error("[Error] stack Peek is wrong") - } + stack.Pop() + + if stack.Length() != 2 { + t.Error("[Error] stack length is wrong after pop") + } + + if stack.Peek() != 6 { + t.Error("[Error] stack Peek is wrong") + } }