+ 1
Data Structures: how to make them?
so i want to make my own data structures, but i have some questions, i am using java is there any way to make a Collection system that doesnt use any current system? like ideally id like to make nodes and have a class that stores the nodes, but i cant think of anyway to have multiple nodes without storing them inside of some pre-existing collection like an array.
5 Answers
+ 10
Nodes point to eachother, thats how they are stored.
If you dont quite understand how a node works, i suggest starting out with a linked list.
It is possible in Java, plus easier since the JVM does the garbage collecting for us.
The basics a node should have are:
pointer to the next node and data it can hold.
the next node should always be null unless its pointing to a new node.
Visual representation
[data | address to next node] -> [data | address to next node] -> [data | address to next node] -> [ null ]
its not exactly an array because we cant just access any node we want; we must traverse if the node isnt first, or in some cases, last
+ 12
Yes you got it ;)
+ 10
yeah haha
Youre welcome :)
+ 2
「HAPPY TO HELP」 thank you for the info, i looked into nodes and now better understand how they relate to each other it has opened a new door, just to make sure i have it right though, a linked list will have a reference to the next node only, a doubly linked list will have a reference to the previous node and next node with the first nodes previous node reference being null and last nodes next reference being null, then when you insert a node in the middle you just update the references of the next and previous nodes at the point of insert?
+ 1
「HAPPY TO HELP」 easy on a conceptual level, the fun part will be implementation, thanks again for all the help!