I have struct Foo with fields Field_1 and Field_2.
package foo
type Custom struct {
start_row int
start_column int
move_row int
move_column int
}
type Foo struct{
Field_1 [100]Custom
Field_2 stack.Stack
}
How can I initialize Foo? Something like this,
new_element := &foo.Foo { [100]foo.Custom{}, stack.Stack {} }
But I need specify stack as container for foo.Custom struct, because I need to access later start_row, start_column like this
Element: = Field_2.Pop()
fmt.Printf("%d
", Element.start_row)
Here is stack implementation
package stack
type Stack struct {
top *Element
size int
}
type Element struct {
value interface{}
next *Element
}
// Get length of the stack
func (s *Stack) Length() int {
return s.size
}
// Push a new element into the stack
func (s *Stack) Push(value interface{}) {
s.top = &Element{value, s.top}
s.size += 1
}
// Remove the top element from the stack and return value
// If stack is empty return nil
func (s *Stack) Pop() (value interface{}) {
if s.size > 0 {
value, s.top = s.top.value, s.top.next
s.size -= 1
return
}
return nil
}