From 5dc6ce8daa3abc1579f2e8935f5658cc038c10ca Mon Sep 17 00:00:00 2001 From: bjt-user Date: Wed, 1 May 2024 15:57:29 +0200 Subject: [PATCH] recursively printing children works --- main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 55995f5..735cd53 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,17 @@ func print_children(heading *heading, headings []heading) { } } +func print_children_recursive(heading *heading, headings []heading) { + //fmt.Printf("pointer of parent: %p\n", heading) + + for index, _ := range headings { + if headings[index].parent == heading { + fmt.Printf("Child of parent %p: %s\n", heading, headings[index].text) + print_children_recursive(&headings[index], headings) + } + } +} + func main() { file_content_raw, err := os.ReadFile(os.Args[1]) @@ -107,7 +118,9 @@ func main() { //print_children(nil, headings) // print all children of the second header - print_children(&headings[1], headings) + //print_children(&headings[1], headings) + + print_children_recursive(nil, headings) fmt.Printf("%v\n", headings)