ā learning tree data structure
I've got some data that I'd like to store for a unity app. The data is perfect for a 3-level tree, but I have never used that data structure before. Currently I'm using a triple layered list, and my code is a MESS.
Does anyone know any good tutorials for me to research? Currently I've tried but can only find tutorials on actual trees, and tutorials explaining how the data structure works, but not how to write the code.
36 Replies
seriously, my code is a mess. here is a snippet.
For a given tree, there is no set depth and different branches can end earlier or later, etc. Every implementation I've seen uses a recursive approach where each notes contains a collection of its own type storing its children
yep
but how do I write a tree in code? I've seen some snippets in tutorials but I have no idea how it works or how to write the code for it
Can you make classes?
unity allows me to but I've never made my own class
I'm 100% self taught so my coding knowledge is near 0 lol
even the most basic concepts are unknown to me
I tend to learn as I go
Haven't used Unity in ages so can't say exactly how to attach a non monobehavior class to your project
It's the same syntax as a script minus the
: MonoBehaviour
and you don't need the Start/Update methodsI mean, I should be able to figure that out
but still, how do I make a tree then?
nevermind attaching it to unity, I don't even know how to write a tree
The class is a data type you can use to define members. So if you have a class called Node, inside it you can define a List<Note>
Each instance will have its own list of itself, the branches going from that node
can each node hold multiple data types?
I've got around 5 variables I'd like to store in each node
You can define more members to it
more members?
Fields properties or methods
so I can have each node in the tree store multiple data types and variables yeah?
Yes, classes can store as much data as you want
oh wait yeah trees are just linked classes right?
Each instance will have its own values for the fields and properties
is there any tutorial or example code that I can read to go through
and try to figure out
because I have no idea where to start when I wanna write the code for it
I barely know how to write a class...
Tree Data Structure
In this article, you will learn about Tree Data Structure.
ah thanks
I'll read through that first then
legit I couldn't find any good youtube tutorials tho
For some reason the class is defined with the Class keyword, that should be lowercase
this?
yes
so it should be
?
š
wtf why my formatting no work
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/there we go
didn't know a space after ```cs caused formatting to yeet out the window š
The examples are pretty advances but the bare minimum you need is the class with a collection of its own type
as long as I can read the code and hopefully figure it out I should be able to derive my own code from that
š¤
yeah no the article didn't really help...
but I got this:
this was an example given to me, if this is right I'll use this as the fundamental to build upon
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.No
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.Nope
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.Bruh
Whatever