235. The most recent common ancestor of the binary search tree Likou question link(opens new window) Given a binary search tree, find the nearest common ancestor of two specified nodes in the tree. class Solution { private: TreeNode* traversal(TreeNode* cur, TreeNode* p, TreeNode* q) { if (cur == NULL) return cur; // middle if (cur->val […]

# Tag: insertion

## [Data structure] Sorting insertion sort and selection sort

Blog homepage: Xiao Wang is sleepy again Column Series: Data Structure People are learning, if they don’t get closer, they will retreat Thank you everyone for liking, collecting, and commenting Table of Contents 1. The concept of sorting and its classification 1.1 Concept of sorting 1.2 Sorting classification 2. Insertion sort 2.1 Direct insertion sort […]

## Data structure – various sorting algorithms (insertion, exchange, selection, merge)

1. Declaration and definition of functions sort.h #pragma once #include <stdio.h> #include <stdlib.h> #define MaxSize 5 typedef int KeyType; typedef char InfoType; typedef struct { KeyType key; //The key here is the value we want to sort InfoType data; }RecType; #ifndef __SORT_H__ #define __SORT_H__ //Insert directly void InsertSort(RecType R[], int n); //Half insertion sort (dichotomy […]

## JDBC implements database batch insertion

Table of Contents 1. Several ways to implement batch insertion using JDBC 2. Use of PreparedStatement addBatch method 3. The difference between Statement and PreparedStatement Using Java Database Connectivity (JDBC) to implement batch insertion can improve the efficiency of database operations, especially when multiple pieces of data need to be inserted at one time. 1. […]

## Overloading of C++ stream insertion and stream extraction!

As a derivative of C language, C++ makes up for many deficiencies in C language and also makes certain optimizations to C language! Today, let’s explain the knowledge related to input/output in C++! And overloading of input/output! , I hope that after reading this article, readers will have a deeper understanding of input/output streams in […]

## Rust Algorithm Ranking – Illustration and Code Implementation of Insertion Sort

The writing process of Rust code is slightly different from that of other languages, because its compiler does not allow any unsafe writing methods, so the longest time spent in the code writing process is finding compilation errors. s reason. This also has advantages – after the code is written, the stability is greatly improved! […]

## Sorting insertion sort and selection sort

In our daily life, sorting is widely used. A useful sorting algorithm can greatly improve the speed. Today we will learn four of the eight major sortings: direct insertion sorting, Hill sorting, selection sorting, Heap sort. Table of Contents 1. Direct insertion sort 2. Hill sorting 3. Select sorting 4. Heap sort 1. Direct insertion […]

## [C++] Implementation of red-black tree insertion operation and verification of whether the red-black tree is correct

Blog homepage: Home Series of columns: C + + Thank you everyone for likingCollecting?Comments Looking forward to making progress with everyone! Article directory Preface 1. Insertion operation of red-black tree 1. Definition of red-black tree nodes 2. Insertion of red-black tree 1.uncle exists and is red 2.uncle does not exist 3.uncle exists and is black […]

## Java handwritten insertion sorting and algorithm case expansion

1. Java handwritten insertion sorting and algorithm case expansion 1.1 Algorithm Mind Map #mermaid-svg-jIZ3LAdg1NLcOvaM {font-family:”trebuchet ms”,verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-jIZ3LAdg1NLcOvaM .error- icon{fill:#552222;}#mermaid-svg-jIZ3LAdg1NLcOvaM .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-jIZ3LAdg1NLcOvaM .edge-thickness-normal{stroke-width:2px;} #mermaid-svg-jIZ3LAdg1NLcOvaM .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-jIZ3LAdg1NLcOvaM .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-jIZ3LAdg1NLcOvaM .edge- pattern-dashed{stroke-dasharray:3;}#mermaid-svg-jIZ3LAdg1NLcOvaM .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-jIZ3LAdg1NLcOvaM .marker{fill:#333333;stroke:#333333; }#mermaid-svg-jIZ3LAdg1NLcOvaM .marker.cross{stroke:#333333;}#mermaid-svg-jIZ3LAdg1NLcOvaM svg{font-family:”trebuchet ms”,verdana,arial,sans-serif;font-size:16px ;}#mermaid-svg-jIZ3LAdg1NLcOvaM .label{font-family:”trebuchet ms”,verdana,arial,sans-serif;color:#333;}#mermaid-svg-jIZ3LAdg1NLcOvaM .cluster-label text{fill: #333;}#mermaid-svg-jIZ3LAdg1NLcOvaM .cluster-label span{color:#333;}#mermaid-svg-jIZ3LAdg1NLcOvaM .label text,#mermaid-svg-jIZ3LAdg1NLcOvaM span{fill:#333;color:#333; }#mermaid-svg-jIZ3LAdg1NLcOvaM .node rect,#mermaid-svg-jIZ3LAdg1NLcOvaM .node circle,#mermaid-svg-jIZ3LAdg1NLcOvaM .node ellipse,#mermaid-svg-jIZ3LAdg1NLcOvaM .node polygon,#mermaid-svg -jIZ3LAdg1NLcOvaM .node path {fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-jIZ3LAdg1NLcOvaM […]

## [C++] Red-black tree principle and insertion implementation (with illustrations and source code)

Red-black tree I. Introduction 2. What is a red-black tree? 1. Concept 2. Nature 3. Build a red-black tree 1. Enumerate two colors 2. Define red-black tree nodes 3. Build a red-black tree 4. Insert 1. Find the insertion position 2. Adjust the red-black tree The parent node is black when inserted The parent node […]