Printing a slice of structs recursively

148 views
Skip to first unread message

erdem erdem

unread,
Sep 1, 2021, 9:55:01 PM9/1/21
to golang-nuts
i need some help with printing a slice of structs which there is a child - parent relation in the struct.
type Emp struct {
        id       int
        name     string
        parentID int
}
probably the best way to do it recursively but i couldnt manage to do
https://play.golang.org/p/jHcbu3uBgOD

Sean Liao

unread,
Sep 2, 2021, 1:03:48 AM9/2/21
to golang-nuts
Try doing it recursively, passing in both the current parent id and indentation level

Michael Ellis

unread,
Sep 2, 2021, 8:30:20 PM9/2/21
to golang-nuts

erdem erdem

unread,
Sep 5, 2021, 1:56:20 PM9/5/21
to Michael Ellis, golang-nuts
sorry to answer you late.
i couldn't find the time to check your responses
first of all, thank you for the answers

Michael i changed your code a bit because there was an unnecessary recursion
if you wanna check it out
here is a new link for it

Michael Ellis <michael...@gmail.com>, 3 Eyl 2021 Cum, 03:30 tarihinde şunu yazdı:
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ae9b334a-67ab-4e5a-a1a6-a4e2a996a3ebn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages