Go

    [Go] context 호출 계층에 따른 결과 테스트하기

    호출 순서(func) : main -> a -> ab -> abc -> abd -> ac -> b 취소 호출(func, time) : main(time.Second * 5) 영향 func : a,b,ab,ac,abc,abd 내용 보강 필요 실행 코드 package main import ( "context" "fmt" "sync" "time" ) func main() { ctx := context.Background() ctx, cancel := context.WithTimeout(ctx, time.Second*5) defer cancel() var wg sync.WaitGroup wg.Add(2) go a(ctx, &wg) go b(ctx, &wg) wg.Wait() } func a(ctx contex..

    [Go] Go를이용한 Stack 구현

    [Go] Go를이용한 Stack 구현

    이번에 GoLang을 배우면서 문법 공부 복습 및 GoLang에서의 Stack은 어떻게 구현될까 궁금해 직접 구현해봤다. package main import ( "errors" "fmt" "log" ) type stack struct { top *node } type node struct { val int next *node } func newStack() *stack { return &stack{ top: nil, } } //LIFO Last In First Out func (s *stack) push(val int) { if s.top == nil { n := &node{val: val, next: nil} s.top = n return } n := &node{val: val, next: s.top}..