Does anybody have good tutorial for branching tree in C ?
I mean a good way to implement branching tree and probably search function in tree.

  • 0
    Opens command line: tree

    There ya go 😂😉
  • 1
    @ScribeOfGoD haha. In C. I would like to understand how it works cause AoC day6 cant be solved without it. Solved day 7 but 6 sits there without star. Thats just not nice.
  • 1
    It's just a struct with arbitrary data part and an array of pointers for the next depth level. Traversing is a recursive function with a for loop inside.

    Or you make the pointer array of dynamic length with calloc, doesn't change much.
  • 0
    Well im of to work so i will look at this in morning.
  • 1
    BTW i found the solution when i thinked about it on my own. just an array of nodes with pointer to previous and next node and the ID of that node.

    And to find that path i just search from the node i need up until i hit beginning and then i take the second node i have to reach and search up until i hit common node. Then i just add the number of steps and done.

    Little weird having "object" in C but hey it worked.
  • 1
    @Haxk20 Objects do not require dedicated language implementation. A lot of other languages with object implementations (python, for example) are written in C and handle objects just fine, because an object is a conceptual thing above what C provides, but not beyond what can be implemented in it.
  • 1
    @powerfulparadox I know. I already said it. I implemented it using "objects" which is just fucking struct in C.
Add Comment