Control please give us a train of thought! ----greedy.
# I used to do a privilege control system, because of the need to modify, and I did not find an effective solution,
# Please give advice, give a general idea, thank you! Requirements are as follows:
# 1. There are multiple children below each father node
# 2. Each child may have a father, and there may be multiple fathers (multiple fathers may differ in rank and
# is a cross phenomenon
# 3. Each father may manage the same child or a different child
# 4. Every time a father lands, he sees only his own children (if the children are different, the landing
# father can only see the children below, if the same, then they see children are the same.
# 5. Each father can add his own father (child?)
The tree-like structure can be obtained by the proposed problem. The key is how to save the tree and how to retrieve it.
After 004 login, you should see (1,001)-[2,004]-(3,007) and (1,002)-[2,004]-(3,003)-(4,007), etc.
and should not see (1,003)-(2,007).
That is, all users searching for children after logging in may be on multiple branches.
has two tables
Table one saves all members information (hereinafter referred to as U), primary key Id_u
Table II is the relationship between members (hereinafter referred to as K), primary key ID
U
Id_u | name | ...
-------+------+----
001 | |
002 | |
003 | |
004 | |
005 | |
006 | |
... | |
Where: Level save levels, next save the subordinate ID, previons save the Superior ID, right save the right-hand neighbor ID
On the specific data organization depending on the algorithm.
Number of traversal algorithm, is very classic!
It is recommended that array calculations, that is, read into an array one at a time, may be more efficient
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service