본문 바로가기

Web Development/CommonSense

[AL&DS] 스택

type Stack []interface{}

// 스택 (LIFO)
func (s *Stack) addStack(_appendNum int) Stack {
	*s = append(*s, _appendNum)
	return *s
}

func (s *Stack) removeStack() interface{} {
	if len(*s) < 0 {
		return 0
	}
	topIdx := len(*s) - 1
	data := (*s)[topIdx]
	*s = (*s)[:topIdx]

	// fmt.Println(*s)
	return data
}

 

'Web Development > CommonSense' 카테고리의 다른 글

[AL&DS] 피보나치  (0) 2022.11.12
[AL&DS] 큐  (0) 2022.11.12
[AL&DS] 삽입정렬  (0) 2022.11.12
[AL&DS] 선형해결법  (0) 2022.11.06
[AL&DS] 버블정렬  (0) 2022.11.06