日期:2014-05-17  浏览次数:20440 次

请教一个树节点的删除算法,请大家过来看看吧
求一个php的算法实现,实现如下:
将一个形如表1的树以表2的形式存储在一张数据库表中,现在希望删除一个子树(例如想删除Red子树)该怎么做呢?
Food
|--Fruit
|----Green
|------Pear
|----Red
|------Cherry
|------Apple
|----Yellow
|------Banana
|--Meat
|----Mutton
|----Beef
|----Pork
(表1)
ID                 parent             title
1                                             Food
2                   Food                   Fruit
3                   Fruit                 Green
4                   Green                 Pear
5                   Fruit                 Red
6                   Red                     Cherry
7                   Fruit                 Yellow
8                   Yellow               Banana
9                   Food                   Meat
10                 Meat                   Mutton
11                 Meat                   Beef
12                 Meat                   Pork
13                 Red                     Apple
(表2)

------解决方案--------------------
递归