tree

package
v0.0.0-...-576931e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Code generated by github.com/goghcrow/go-co DO NOT EDIT.

Index

Constants

View Source
const (
	PreOrder  WalkMode = 0
	InOrder            = 1
	PostOrder          = 2
)

Variables

This section is empty.

Functions

func Match

func Match[V comparable](rootA, rootB *Node[V], mode WalkMode) bool

Match the same iterating path

func Walk

func Walk[V any](n *Node[V], mode WalkMode) (_ ʂɘʠ.Iterator[V])
func Walk[V any](n *Node[V], mode WalkMode) (_ Iter[V]) {
	if n == nil {
		return
	}
	switch mode {
	case PreOrder:
		Yield(n.Val)
		YieldFrom(Walk(n.Left, mode))
		YieldFrom(Walk(n.Right, mode))
	case InOrder:
		YieldFrom(Walk(n.Left, mode))
		Yield(n.Val)
		YieldFrom(Walk(n.Right, mode))
	case PostOrder:
		YieldFrom(Walk(n.Left, mode))
		YieldFrom(Walk(n.Right, mode))
		Yield(n.Val)
	default:
		panic("unknown walk mode")
	}
	return
}

Types

type Node

type Node[V any] struct {
	Val         V
	Left, Right *Node[V]
}

type WalkMode

type WalkMode int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL