Home Backend Development PHP Tutorial 请问一个树节点的删除算法,请大家过来看看吧

请问一个树节点的删除算法,请大家过来看看吧

Jun 13, 2016 pm 01:42 PM
nbsp red

请教一个树节点的删除算法,请大家过来看看吧
求一个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)

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

FiiO CP13 cassette player launches with transparent retro look FiiO CP13 cassette player launches with transparent retro look Jun 16, 2024 am 09:52 AM

TheFiiOCP13cassetteplayerwasannouncedinJanuary.Now,FiiOisexpandingitsportfoliowithtwonewmodels-onewitharedfrontandonewithatransparentfront.Thelatternotonlyperfectlymatchestheretrocharmoftheangulardesign,butalso

What are the blockchain data analysis tools? What are the blockchain data analysis tools? Feb 21, 2025 pm 10:24 PM

The rapid development of blockchain technology has brought about the need for reliable and efficient analytical tools. These tools are essential to extract valuable insights from blockchain transactions in order to better understand and capitalize on their potential. This article will explore some of the leading blockchain data analysis tools on the market, including their capabilities, advantages and limitations. By understanding these tools, users can gain the necessary insights to maximize the possibilities of blockchain technology.

How to cancel your Apple subscription How to cancel your Apple subscription Oct 31, 2023 pm 11:13 PM

You can easily cancel AppleOne (like AppleOne) subscriptions, as well as third-party AppStore subscriptions, on your iPhone, iPad, or Mac. Apple offers a variety of services that Apple device owners can subscribe to, including AppleMusic, AppleTV+, AppleArcade, iCloud+, AppleNews+, and AppleFitness+. It also offers these services as a bundled subscription called Apple One. Apple in March 2023 made significant price increases for several of its services, including Apple TV+, Apple Arcade and

Fix: Copilot not working on Windows 11 23H2 Fix: Copilot not working on Windows 11 23H2 Nov 08, 2023 pm 03:09 PM

The latest feature update for Windows 11 is here, and it brings various app updates and improvements, however, many people are reporting that Windows 1123H2 does not have Copilot. This is unfortunate, especially if you're looking forward to trying out new AI assistants. We at Windows Report have encountered the same problem, and in today's guide we will show you some potential solutions that may help if Windows 11 Copilot is missing. How to enable Copilot on 23H2? How do we test, review and score? Over the past 6 months, we have been working hard to establish a new review system for how we produce content. use it

See all articles