- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我有一个包含字段 Field_1 和 Field_2 的结构 Foo。
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
}
如何初始化 Foo?像这样,
new_element := &foo.Foo { [100]foo.Custom{}, stack.Stack {} }
但是我需要指定stack作为foo.Custom struct的容器,因为我需要像这样访问后面的start_row, start_column
Element: = Field_2.Pop()
fmt.Printf("%d \n", Element.start_row)
这里是堆栈实现
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
}
最佳答案
几点:
Custom
中的所有字段都不会导出,您不能直接从不同的包中修改它们。
您不能那样创建 Foo
,但是由于它是一个数组,您可以简单地使用 new_element := &foo.Foo{Field_2: Stack{}}
.
关于syntax - 如何将自定义结构放入堆栈然后能够访问所有字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30133844/
我正在使用 Java 编写一个时钟程序,该程序能够“滴答作响”,但它存在问题。我认为它与 getter 和 setter 或 toString() 方法有关。 计数器类 package clock;
const Index = () => { // Ref Links const frefLinks = { 1: useRef(1), 2: useRef(2), 3: useRef(3
所以我读了here不能 pickle 装饰函数。确实: import multiprocessing as mp def deco(f): def wrapper(*args, **kwarg
我在go1.11.2 linux/amd64 版本。当包godog使用 go get github.com/DATA-DOG/godog/ 安装,godog 可执行文件在 $GOPATH/bin/中创
如何正确压缩字符串,以便 PHP 能够解压缩? 我试过这个: public static byte[] compress(String string) throws IOException {
我们这里的问题是表明 在测试中使用 Kleene 代数。 在 b 的值由 p 保留的情况下,我们有交换条件 bp = pb;两个程序之间的等价性简化为等式 在 b 的值不被 p 保留的情况下,我们有交
我有一个与我的网络相关的非常奇怪的问题,我在具有多个接口(interface)的 VirtualBox 上安装了 RDO Grizzly OpenStack。 虚拟盒子: eth0 - managem
我正在尝试使用 Passport.js授权谷歌OAuth2在 Node.js .我整个星期都在尝试让它工作,但不知道为什么它不工作,所以现在我求助于 stack 寻求一些潜在的帮助。我已经尝试了所有在
我是一名优秀的程序员,十分优秀!