Algorithm-Red black tree rotation

Source: Internet
Author: User

(citation) https://studygolang.com/articles/7014

The rotation of the tree includes the left and right spins, illustrated below


Left-hand: with P as the pivot, n the original parent node p as the left child of the N-node, the left child of the original N-node becomes the right child of P-node, which is completed.

Right: Similar to the left hand, just the right child of the N node becomes the child of the P node.

A few notes are required:

  1. The left side of the node must have a right child, right-handed must have left child.
  2. If n is rotated into a root node, it is important to remember to point root pointer root in the rbtree struct to N, which is an error-prone place.

Algorithm-Red black tree rotation

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.