1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
type TreeNode struct { value int left, right *TreeNode }
func (MyNode TreeNode) print() { fmt.Println(MyNode.value) }
type MyNode struct{ node *TreeNode }
func (MyNode *MyNode ) RightReversal() { if MyNode == nil { fmt.Printf("node does not exist") return } MyNode.node.right.print() MyNode.node.print() MyNode.node.left.print() }
var node = TreeNode{value: 1} node.setVal(4) node.left = &TreeNode{value:12} node.right = &TreeNode{value:7}
var mine_node = &MyNode{&node} mine_node.RightReversal()
type Slice []interface{}
func (q *Slice) Add(val interface{}) { *q = append(*q, val.(int)) }
func (q *Slice) Pop() interface{} { head := (*q)[0] *q = (*q)[1:] return head.(int) }
|