O
O
Oblomov952016-12-07 11:01:51
go
Oblomov95, 2016-12-07 11:01:51

How to properly build a tree structure (Golang) and how to work with it?

There are a lot of examples on the Internet about building binary trees and working with them, but I could not find a clear explanation of working with non-binary trees, perhaps because there is not much difference. But I don't fully understand how it works.
I need to implement a search tree for a certain category in a YML file, depending on the selected level, if level 0 is a site, level 1 is a category level without parents, level 2 is all categories whose parent is the one who is at the top of the 1st level.
YML structure

type Yml struct {
  XMLName xml.Name `xml:"yml_catalog"`
  Date    string   `xml:"date,attr"`
  Shop    []Shop   `xml:"shop"`
}

type Shop struct {
  Name       string     `xml:"name"`
  Company    string     `xml:"company"`
  URL        string     `xml:"url"`
  Categories []Category `xml:"categories>category"`
  Offers     []Offer    `xml:"offers>offer"`
}

type Category struct {
  ID       int    `xml:"id,attr"`
  ParentID int    `xml:"parentId,attr"`
  Category string `xml:",chardata"`
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question