You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
496 B
Go
27 lines
496 B
Go
3 years ago
|
package trie
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestTrie(t *testing.T) {
|
||
|
trie := NewTrie()
|
||
|
|
||
|
// 指令集
|
||
|
words := []string{"j", "c", "w", "s", "m"}
|
||
|
|
||
|
// 构建 前缀树
|
||
|
for _, word := range words {
|
||
|
trie.Insert(word)
|
||
|
}
|
||
|
|
||
|
// 待搜索的连续指令 玩家自由搭配
|
||
|
search := "jc3sm1c2m2c4m3" // 加入游戏 生产3 上路兵 生产2 中路兵 生产4 下路兵
|
||
|
if trie.Exists(search) {
|
||
|
fmt.Println("可以用 ", search)
|
||
|
} else {
|
||
|
fmt.Println("啊 还没能匹配", search)
|
||
|
}
|
||
|
}
|