Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kag1

Use a Linked List?

This topic is 5219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I was given the task of making...almost like a family tree sort of program..for example.. i have a Person Object, well in this person object, it should have... object person { father; mother; number of children; (then pointers or somethign to every child) number of wives; (pointers to every wife) id number; lot number; date born; date died; } and i need to be able to add children at any time, and able to wives or change things and whatnot..and like in the program, if I were to click on like father..it would take me to his person structure and display all his information....I thought that I should just use class objects with link lists connecting them.. just checking with you guys to see if that would be the way to go... but the problem kinda comes in if this person decides to have another child..how do i just make up another child at runtime? sorry for the complete sloppiness, hope i got my message across of what i''m trying to do thank you

Share this post


Link to post
Share on other sites
Advertisement
Yes, declare your child pointer as a list (i think lists are more appropriate in this case) of person*, and you should be good to go.

Could also use double pointers - person **children.

Share this post


Link to post
Share on other sites
quote:

..how do i just make up another child at runtime?


Did you ask your girlfriend/wife ?

Aside from that, more than using the STL containers vector or list, you have a simple problem of database modelization. Did you have any course in database modelization ? Have you checked the MERISE method ?

There are here some key definitions to coin up before implementing structs:
- a wife, a husband, a child are persons.
- a person has a first names, a last name, a birth date and a death date.
- a person is the child of two other distinct persons.
- a person can be married with one other person. This relation holds a wedding date and an end date (divorce or death of one of the persons).

Looking from these definitions and applying the MERISE method will get you the needed structs and define the needed algorithms to derive the functionalities you need.

Hope that helps.

Ghostly yours,
Red.

Share this post


Link to post
Share on other sites
You could almost use an extended binary tree where instead of just a left and right pointer within each node you could have a list/array of pointers that would point to the descendants.

Share this post


Link to post
Share on other sites
Looking through the answers, I wonder how people manage both occurences and keep a log of changes in the family:
- wedding between two divorced people and already having children.
- adoption of a new child by parents and trying to relate this adopted child to the old and new parents.
I find the design faulty at the light of these two cases.
If you don''t have any of these two cases, then the design''s enough to get by.





Ghostly yours,
Red.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!