红黑树的c++完整实现源码

红黑树的c++完整实现源码


作者:July、saturnman。
时间:二零一一年三月二十九日。
出处:http://blog.csdn.net/v_JULY_v
声明:版权所有,侵权必究。
-------------------------------------------

前言:
    本人的原创作品红黑树系列文章,至此,已经写到第5篇了。虽然第三篇文章:红黑树的c源码实现与剖析,用c语言完整实现过红黑树,但个人感觉,代码还是不够清晰。特此,再奉献出一份c++的完整实现源码,以飨读者。

    此份c++实现源码,代码紧凑了许多,也清晰了不少,同时采取c++类实现的方式,代码也更容易维护以及重用。ok,有任何问题,欢迎指正。

版权声明
    本BLOG内的此红黑树系列,总计六篇文章,是整个国内有史以来有关红黑树的最具代表性,最具完整性,最具参考价值的资料。且,本人对此红黑树系列全部文章,享有版权,任何人,任何组织,任何出版社不得侵犯本人版权相关利益,违者追究法律责任。谢谢。

红黑树的c++完整实现源码

    本文包含红黑树c++实现的完整源码,所有的解释都含在注释中,所有的有关红黑树的原理及各种插入、删除操作的情况,都已在本人的红黑树系列的前4篇文章中,一一阐述。且在此红黑树系列第五篇文章中:红黑树从头至尾插入和删除结点的全程演示图,把所有的插入、删除情况都一一展示尽了。
    因此,有关红黑树的全部原理,请参考其它文章,重点可参考此文:红黑树算法的实现与剖析。因此,相关原理,本文不再赘述。

    ok,以下,即是红黑树c++实现的全部源码,先是RBTree.h,然后是RBTree.cpp。

 

RBTree.h//file RBTree.h //written by saturnman,20101008。 //updated by July,20110329。 /*----------------------------------------------- 版权声明: July和saturnman对此份红黑树的c++实现代码享有全部的版权, 谢绝转载,侵权必究。 ------------------------------------------------*/ #ifndef _RB_TREE_H_ #define _RB_TREE_H_ #include<iostream> #include<string> #include<sstream> #include<fstream> using namespace std; template<class KEY,class U> class RB_Tree { private: RB_Tree(const RB_Tree& input){} const RB_Tree& operator=(const RB_Tree& input){} private: enum COLOR{RED,BLACK}; class RB_Node { public: RB_Node() { //RB_COLOR = BLACK; right = NULL; left = NULL; parent = NULL; } COLOR RB_COLOR; RB_Node* right; RB_Node* left; RB_Node* parent; KEY key; U data; }; public: RB_Tree() { this->m_nullNode = new RB_Node(); this->m_root = m_nullNode; this->m_nullNode->right = this->m_root; this->m_nullNode->left = this->m_root; this->m_nullNode->parent = this->m_root; this->m_nullNode->RB_COLOR = BLACK; } bool Empty() { if(this->m_root == this->m_nullNode) { return true; } else { return false; } } //查找key RB_Node* find(KEY key) { RB_Node* index = m_root; while(index != m_nullNode) { if(key<index->key) { index = index->left; //比当前的小,往左 } else if(key>index->key) { index = index->right; //比当前的大,往右 } else { break; } } return index; } //--------------------------插入结点总操作---------------------------------- //全部的工作,都在下述伪代码中: /*RB-INSERT(T, z) 1 y ← nil[T] // y 始终指向 x 的父结点。 2 x ← root[T] // x 指向当前树的根结点, 3 while x ≠ nil[T] 4 do y ← x 5 if key[z] < key[x] //向左,向右.. 6 then x ← left[x] 7 else x ← right[x] //为了找到合适的插入点,x探路跟踪路径,直到x成为NIL 为止。 8 p[z] ← y //y置为 插入结点z 的父结点。 9 if y = nil[T] 10 then root[T] ← z 11 else if key[z] < key[y] 12 then left[y] ← z 13 else right[y] ← z //此 8-13行,置z 相关的指针。 14 left[z] ← nil[T] 15 right[z] ← nil[T] //设为空, 16 color[z] ← RED //将新插入的结点z作为红色 17 RB-INSERT-FIXUP(T, z) */ //因为将z着为红色,可能会违反某一红黑性质, //所以需要调用下面的RB-INSERT-FIXUP(T, z)来保持红黑性质。 bool Insert(KEY key,U data) { RB_Node* insert_point = m_nullNode; RB_Node* index = m_root; while(index!=m_nullNode) { insert_point = index; if(key<index->key) { index = index->left; } else if(key>index->key) { index = index->right; } else { return false; } } RB_Node* insert_node = new RB_Node(); insert_node->key = key; insert_node->data = data; insert_node->RB_COLOR = RED; insert_node->right = m_nullNode; insert_node->left = m_nullNode; if(insert_point==m_nullNode) //如果插入的是一颗空树 { m_root = insert_node; m_root->parent = m_nullNode; m_nullNode->left = m_root; m_nullNode->right = m_root; m_nullNode->parent = m_root; } else { if(key<insert_point->key) { insert_point->left = insert_node; } else { insert_point->right = insert_node; } insert_node->parent = insert_point; } InsertFixUp(insert_node); //调用InsertFixUp修复红黑树性质。 } //---------------------插入结点性质修复-------------------------------- //3种插入情况,都在下面的伪代码中(未涉及到所有全部的插入情况)。 /* RB-INSERT-FIXUP(T, z) 1 while color[p[z]] = RED 2 do if p[z] = left[p[p[z]]] 3 then y ← right[p[p[z]]] 4 if color[y] = RED 5 then color[p[z]] ← BLACK ? Case 1 6 color[y] ← BLACK ? Case 1 7 color[p[p[z]]] ← RED ? Case 1 8 z ← p[p[z]] ? Case 1 9 else if z = right[p[z]] 10 then z ← p[z] ? Case 2 11 LEFT-ROTATE(T, z) ? Case 2 12 color[p[z]] ← BLACK ? Case 3 13 color[p[p[z]]] ← RED ? Case 3 14 RIGHT-ROTATE(T, p[p[z]]) ? Case 3 15 else (same as then clause with "right" and "left" exchanged) 16 color[root[T]] ← BLACK */ //然后的工作,就非常简单了,即把上述伪代码改写为下述的c++代码: void InsertFixUp(RB_Node* node) { while(node->parent->RB_COLOR==RED) { if(node->parent==node->parent->parent->left) // { RB_Node* uncle = node->parent->parent->right; if(uncle->RB_COLOR == RED) //插入情况1,z的叔叔y是红色的。 { node->parent->RB_COLOR = BLACK; uncle->RB_COLOR = BLACK; node->parent->parent->RB_COLOR = RED; node = node->parent->parent; } else if(uncle->RB_COLOR == BLACK ) //插入情况2:z的叔叔y是黑色的,。 { if(node == node->parent->right) //且z是右孩子 { node = node->parent; RotateLeft(node); } else //插入情况3:z的叔叔y是黑色的,但z是左孩子。 { node->parent->RB_COLOR = BLACK; node->parent->parent->RB_COLOR = RED; RotateRight(node->parent->parent); } } } else //这部分是针对为插入情况1中,z的父亲现在作为祖父的右孩子了的情况,而写的。 //15 else (same as then clause with "right" and "left" exchanged) { RB_Node* uncle = node->parent->parent->left; if(uncle->RB_COLOR == RED) { node->parent->RB_COLOR = BLACK; uncle->RB_COLOR = BLACK; uncle->parent->RB_COLOR = RED; node = node->parent->parent; } else if(uncle->RB_COLOR == BLACK) { if(node == node->parent->left) { node = node->parent; RotateRight(node); //与上述代码相比,左旋改为右旋 } else { node->parent->RB_COLOR = BLACK; node->parent->parent->RB_COLOR = RED; RotateLeft(node->parent->parent); //右旋改为左旋,即可。 } } } } m_root->RB_COLOR = BLACK; } //左旋代码实现 bool RotateLeft(RB_Node* node) { if(node==m_nullNode || node->right==m_nullNode) { return false;//can't rotate } RB_Node* lower_right = node->right; lower_right->parent = node->parent; node->right=lower_right->left; if(lower_right->left!=m_nullNode) { lower_right->left->parent = node; } if(node->parent==m_nullNode) //rotate node is root { m_root = lower_right; m_nullNode->left = m_root; m_nullNode->right= m_root; //m_nullNode->parent = m_root; } else { if(node == node->parent->left) { node->parent->left = lower_right; } else { node->parent->right = lower_right; } } node->parent = lower_right; lower_right->left = node; } //右旋代码实现 bool RotateRight(RB_Node* node) { if(node==m_nullNode || node->left==m_nullNode) { return false;//can't rotate } RB_Node* lower_left = node->left; node->left = lower_left->right; lower_left->parent = node->parent; if(lower_left->right!=m_nullNode) { lower_left->right->parent = node; } if(node->parent == m_nullNode) //node is root { m_root = lower_left; m_nullNode->left = m_root; m_nullNode->right = m_root; //m_nullNode->parent = m_root; } else { if(node==node->parent->right) { node->parent->right = lower_left; } else { node->parent->left = lower_left; } } node->parent = lower_left; lower_left->right = node; } //--------------------------删除结点总操作---------------------------------- //伪代码,不再贴出,详情,请参考此红黑树系列第二篇文章: //经典算法研究系列:五、红黑树算法的实现与剖析: //http://blog.csdn.net/v_JULY_v/archive/2010/12/31/6109153.aspx。 bool Delete(KEY key) { RB_Node* delete_point = find(key); if(delete_point == m_nullNode) { return false; } if(delete_point->left!=m_nullNode && delete_point->right!=m_nullNode) { RB_Node* successor = InOrderSuccessor(delete_point); delete_point->data = successor->data; delete_point->key = successor->key; delete_point = successor; } RB_Node* delete_point_child; if(delete_point->right!=m_nullNode) { delete_point_child = delete_point->right; } else if(delete_point->left!=m_nullNode) { delete_point_child = delete_point->left; } else { delete_point_child = m_nullNode; } delete_point_child->parent = delete_point->parent; if(delete_point->parent==m_nullNode)//delete root node { m_root = delete_point_child; m_nullNode->parent = m_root; m_nullNode->left = m_root; m_nullNode->right = m_root; } else if(delete_point == delete_point->parent->right) { delete_point->parent->right = delete_point_child; } else { delete_point->parent->left = delete_point_child; } if(delete_point->RB_COLOR==BLACK && !(delete_point_child==m_nullNode && delete_point_child->parent==m_nullNode)) { DeleteFixUp(delete_point_child); } delete delete_point; return true; } //---------------------删除结点性质修复----------------------------------- //所有的工作,都在下述23行伪代码中: /* RB-DELETE-FIXUP(T, x) 1 while x ≠ root[T] and color[x] = BLACK 2 do if x = left[p[x]] 3 then w ← right[p[x]] 4 if color[w] = RED 5 then color[w] ← BLACK ? Case 1 6 color[p[x]] ← RED ? Case 1 7 LEFT-ROTATE(T, p[x]) ? Case 1 8 w ← right[p[x]] ? Case 1 9 if color[left[w]] = BLACK and color[right[w]] = BLACK 10 then color[w] ← RED ? Case 2 11 x p[x] ? Case 2 12 else if color[right[w]] = BLACK 13 then color[left[w]] ← BLACK ? Case 3 14 color[w] ← RED ? Case 3 15 RIGHT-ROTATE(T, w) ? Case 3 16 w ← right[p[x]] ? Case 3 17 color[w] ← color[p[x]] ? Case 4 18 color[p[x]] ← BLACK ? Case 4 19 color[right[w]] ← BLACK ? Case 4 20 LEFT-ROTATE(T, p[x]) ? Case 4 21 x ← root[T] ? Case 4 22 else (same as then clause with "right" and "left" exchanged) 23 color[x] ← BLACK */ //接下来的工作,很简单,即把上述伪代码改写成c++代码即可。 void DeleteFixUp(RB_Node* node) { while(node!=m_root && node->RB_COLOR==BLACK) { if(node == node->parent->left) { RB_Node* brother = node->parent->right; if(brother->RB_COLOR==RED) //情况1:x的兄弟w是红色的。 { brother->RB_COLOR = BLACK; node->parent->RB_COLOR = RED; RotateLeft(node->parent); } else //情况2:x的兄弟w是黑色的, { if(brother->left->RB_COLOR == BLACK && brother->right->RB_COLOR == BLACK) //且w的俩个孩子都是黑色的。 { brother->RB_COLOR = RED; node = node->parent; } else if(brother->right->RB_COLOR == BLACK) //情况3:x的兄弟w是黑色的,w的右孩子是黑色(w的左孩子是红色)。 { brother->RB_COLOR = RED; brother->left->RB_COLOR = BLACK; RotateRight(brother); } else if(brother->right->RB_COLOR == RED) //情况4:x的兄弟w是黑色的,且w的右孩子时红色的。 { brother->RB_COLOR = node->parent->RB_COLOR; node->parent->RB_COLOR = BLACK; brother->right->RB_COLOR = BLACK; RotateLeft(node->parent); node = m_root; } } } else //下述情况针对上面的情况1中,node作为右孩子而阐述的。 //22 else (same as then clause with "right" and "left" exchanged) //同样,原理一致,只是遇到左旋改为右旋,遇到右旋改为左旋,即可。其它代码不变。 { RB_Node* brother = node->parent->left; if(brother->RB_COLOR == RED) { brother->RB_COLOR = BLACK; node->parent->RB_COLOR = RED; RotateRight(node->parent); } else { if(brother->left->RB_COLOR==BLACK && brother->right->RB_COLOR == BLACK) { brother->RB_COLOR = RED; node = node->parent; } else if(brother->left->RB_COLOR==BLACK) { brother->RB_COLOR = RED; brother->right->RB_COLOR = BLACK; RotateLeft(brother); } else if(brother->left->RB_COLOR==RED) { brother->RB_COLOR = node->parent->RB_COLOR; node->parent->RB_COLOR = BLACK; brother->left->RB_COLOR = BLACK; RotateRight(node->parent); node = m_root; } } } } m_nullNode->parent = m_root; //最后将node置为根结点, node->RB_COLOR = BLACK; //并改为黑色。 } // inline RB_Node* InOrderPredecessor(RB_Node* node) { if(node==m_nullNode) //null node has no predecessor { return m_nullNode; } RB_Node* result = node->left; //get node's left child while(result!=m_nullNode) //try to find node's left subtree's right most node { if(result->right!=m_nullNode) { result = result->right; } else { break; } } //after while loop result==null or result's right child is null if(result==m_nullNode) { RB_Node* index = node->parent; result = node; while(index!=m_nullNode && result == index->left) { result = index; index = index->parent; } result = index; // first right parent or null } return result; } // inline RB_Node* InOrderSuccessor(RB_Node* node) { if(node==m_nullNode) //null node has no successor { return m_nullNode; } RB_Node* result = node->right; //get node's right node while(result!=m_nullNode) //try to find node's right subtree's left most node { if(result->left!=m_nullNode) { result = result->left; } else { break; } } //after while loop result==null or result's left child is null if(result == m_nullNode) { RB_Node* index = node->parent; result = node; while(index!=m_nullNode && result == index->right) { result = index; index = index->parent; } result = index; //first parent's left or null } return result; } //debug void InOrderTraverse() { InOrderTraverse(m_root); } void CreateGraph(string filename) { //delete } void InOrderCreate(ofstream& file,RB_Node* node) { //delete } void InOrderTraverse(RB_Node* node) { if(node==m_nullNode) { return; } else { InOrderTraverse(node->left); cout<<node->key<<endl; InOrderTraverse(node->right); } } ~RB_Tree() { clear(m_root); delete m_nullNode; } private: // utility function for destructor to destruct object; void clear(RB_Node* node) { if(node==m_nullNode) { return ; } else { clear(node->left); clear(node->right); delete node; } } private: RB_Node *m_nullNode; RB_Node *m_root; }; #endif /*_RB_TREE_H_*/

 

 RBTree.cpp//file RBTree.cpp //written by saturnman,20101008。 //updated by July,20110329。 //此处,省去了所有要包含的头文件 //主函数测试用例 int main() { RB_Tree<int,int> tree; vector<int> v; for(int i=0;i<20;++i) { v.push_back(i); } random_shuffle(v.begin(),v.end()); copy(v.begin(),v.end(),ostream_iterator<int>(cout," ")); cout<<endl; stringstream sstr; for(i=0;i<v.size();++i) { tree.Insert(v[i],i); cout<<"insert:"<<v[i]<<endl; //添加结点 } for(i=0;i<v.size();++i) { cout<<"Delete:"<<v[i]<<endl; tree.Delete(v[i]); //删除结点 tree.InOrderTraverse(); } cout<<endl; tree.InOrderTraverse(); return 0; }

 

运行效果图(先是一一插入各结点,然后再删除所有的结点):8394323_1301370089011Q.jpg8394323_1301370089YyS6.jpg8394323_1301370089Z4jt.jpg

 

参考文献,本人的原创作品红黑树系列的前五篇文章:

4、一步一图一代码,R-B Tree1、教你透彻了解红黑树5、红黑树插入和删除结点的全程演示3、红黑树的c源码实现与剖析2、红黑树算法的实现与剖析6、致谢:http://saturnman.blog.163.com/

完。

 

版权所有。谢绝转载,杜绝一切的侵犯版权的任何举动。
违者,必定追究法律责任。谢谢,各位。

转载于:https://www.cnblogs.com/v-July-v/archive/2011/03/29/2002183.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/475683.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[Kesci] 新人赛 · 员工满意度预测

文章目录1. 导入工具包2. 读取数据3. 特征处理3.1 数字特征归一化3.2 文字特征处理3.3 特征合并4. 定义模型训练5. 预测6. 新人赛结果竞赛地址 使用 sklearn Pipeline 模板 1. 导入工具包 %matplotlib inline import numpy as np import matplotlib.pyplot as plt plt.rcPar…

webusercontrol ajax,ASP.NET页面使用AjaxPro2完成JS调用后台方法

一、首先下载AjaxPro.2.dll(附下载地址)百度网盘链接&#xff1a;https://pan.baidu.com/s/1r87DE1Tza9F4NbJwTCS1AQ提取码&#xff1a;10p6二、在Visual studio中创建空Web项目&#xff0c;并将AjaxPro.2.dll复制到bin目录下&#xff0c;包括在项目中三、打开Web.config文件&a…

LeetCode 1109. 航班预订统计(差分思想)

1. 题目 这里有 n 个航班&#xff0c;它们分别从 1 到 n 进行编号。 我们这儿有一份航班预订表&#xff0c;表中第 i 条预订记录 bookings[i] [i, j, k] 意味着我们在从 i 到 j 的每个航班上预订了 k 个座位。 请你返回一个长度为 n 的数组 answer&#xff0c;按航班编号顺…

ajax点击事件无法触发,解决jQuery Ajax动态新增节点无法触发点击事件的问题_婳祎_前端开发者...

在写ajax加载数据的时候发现&#xff0c;后面添加进来的demo节点元素&#xff0c;失去了之前的点击事件。为什么点击事件失效&#xff0c;我们该怎么去解决呢?其实最简单的方法就是直接在标签中写οnclick””&#xff0c;但是这样写其实是有点low的&#xff0c;最好的方式还是…

OSS音频编程概述(DSP部分)

一、 音频概念 音频信号是一种连续变化的模拟信号&#xff0c;但计算机只能处理和记录二进制的数字信号&#xff0c;由自然音源得到的音频信号必须经过一定的变换&#xff0c;成为数字音频信号之后&#xff0c;才能送到计算机中作进一步的处理。 对于OSS编程来说&#xff0c;需…

LeetCode 853. 车队(排序)

1. 题目 N 辆车沿着一条车道驶向位于 target 英里之外的共同目的地。 每辆车 i 以恒定的速度 speed[i] &#xff08;英里/小时&#xff09;&#xff0c;从初始位置 position[i] &#xff08;英里&#xff09; 沿车道驶向目的地。 一辆车永远不会超过前面的另一辆车&#xff…

测试服务器性能常用算法,服务器性能剖析(profiling)之——简介

性能剖析(profiling)是专注于测量服务器时间花费在哪里的一种技术&#xff0c;这里“性能即响应时间”。测量是一项很有挑战性的工作&#xff0c;并且分析结果也同样有挑战性&#xff0c;测出时间花在哪里&#xff0c;和知道为什么花在那里是两码事……性能剖析一般有两个步骤&…

LeetCode 815. 公交路线(最少换乘,BFS)

1. 题目 我们有一系列公交路线。每一条路线 routes[i] 上都有一辆公交车在上面循环行驶。 例如&#xff0c;有一条路线 routes[0] [1, 5, 7]&#xff0c;表示第一辆 (下标为0) 公交车会一直按照 1->5->7->1->5->7->1->… 的车站路线行驶。 假设我们从 …

王者荣耀8月15日服务器维护,王者荣耀8月15日更新维护到什么时候 王者荣耀8月15日更新时间分享...

《王者荣耀》5V5英雄公平对战手游&#xff0c;腾讯最新MOBA大作&#xff01;5V5、3v3、1v1&#xff0c;多样模式一键体验&#xff0c;海量英雄随心选择&#xff01;10秒实时跨区匹配&#xff0c;与好友组队...类型&#xff1a;动作冒险大小&#xff1a;792.06M语言&#xff1a;…

第五章 基元类型、引用类型、值类型 CLR学习第五课

一、基元类型&#xff1a;编译器直接支持的数据类型称为基元类型&#xff08;如int类型其对于的是system。int32&#xff09;。二、类型溢出&#xff0c;可以用checked 和unchecked进行类型溢出检查和不进行类型溢出检查。一个奇怪的问题&#xff0c;2个byte类型相加的结果居然…

LeetCode 640. 求解方程(字符串)

1. 题目 求解一个给定的方程&#xff0c;将x以字符串"x#value"的形式返回。该方程仅包含’’&#xff0c;’ - 操作&#xff0c;变量 x 和其对应系数。 如果方程没有解&#xff0c;请返回“No solution”。 如果方程有无限解&#xff0c;则返回“Infinite solutio…

幻侠修仙服务器维护,幻侠修仙常见问题_幻侠修仙问答_疑难解答_九游手机游戏...

幻侠修仙官网安卓正式版带来震撼无限的修仙剧情模式&#xff0c;让你去体验无尽的冒险传说&#xff0c;带来真实的玄幻与小说的经典模式&#xff0c;还有特节等你还原出来&#xff1b;经历五行天劫的磨炼&#xff0c;我们的修仙之路一日千里&#xff0c;在挂机战斗的逍遥路途之…

LeetCode 84. 柱状图中最大的矩形(单调递增栈)

文章目录1. 题目2. 解题1. 题目 题目链接 给定 n 个非负整数&#xff0c;用来表示柱状图中各个柱子的高度。每个柱子彼此相邻&#xff0c;且宽度为 1 。 求在该柱状图中&#xff0c;能够勾勒出来的矩形的最大面积。 以上是柱状图的示例&#xff0c;其中每个柱子的宽度为 1&am…

option

The Tk command option acts on the "option database". [option add] pattern value ?priority? [option clear] option get window name class [option readfile] fileName ?priority?转载于:https://www.cnblogs.com/greencolor/archive/2011/04/10/…

LeetCode 30. 串联所有单词的子串(字符串哈希)

1. 题目 给定一个字符串 s 和一些长度相同的单词 words。找出 s 中恰好可以由 words 中所有单词串联形成的子串的起始位置。 注意子串要与 words 中的单词完全匹配&#xff0c;中间不能有其他字符&#xff0c;但不需要考虑 words 中单词串联的顺序。 示例 1&#xff1a; 输入…

水晶报表-控制结构-For 循环(Crystal 语法)

For 循环使您能够对一系列表达式多次求值。这不同于 If 和 Select 表达式&#xff0c;在 If 和 Select 语句中&#xff0c;程序在对公式求值时几乎同时传递每个语句。 如果事先知道需要对语句求值的次数&#xff0c;最好使用 For 循环。 使用 For 循环假设要反转 {客户.客户名…

LeetCode 57. 插入区间(一次遍历)

1. 题目 给出一个无重叠的 &#xff0c;按照区间起始端点排序的区间列表。 在列表中插入一个新的区间&#xff0c;你需要确保列表中的区间仍然有序且不重叠&#xff08;如果有必要的话&#xff0c;可以合并区间&#xff09;。 示例 1: 输入: intervals [[1,3],[6,9]], newI…

Windows下usb接口驱动技术(一)

Windows下usb接口芯片的驱动技术一、 USB概述 USB的英文全称为Universal Serial Bus,中文含义是通用串行总线&#xff0c;是由Conpaq、DEC、IBM、Inter、Microsoft、NEC和Northen Telecom等公司为简化PC与外设之间的互连而共同研究开发的一种免费的标准化连接器&#x…

LeetCode 363. 矩形区域不超过 K 的最大数值和(DP+set二分查找)

1. 题目 给定一个非空二维矩阵 matrix 和一个整数 k&#xff0c;找到这个矩阵内部不大于 k 的最大矩形和。 示例: 输入: matrix [[1,0,1],[0,-2,3]], k 2 输出: 2 解释: 矩形区域 [[0, 1], [-2, 3]] 的数值和是 2&#xff0c; 且 2 是不超过 k 的最大数字&#xff08;k 2…

实体框架的惨痛教训

个人评价:通过半年的开发,项目已经运营.但回想起来,整个项目中遇到了许多的问题,还好需求策划上一直很好(原因在于老板原来就是一个产品总监且目前的策划都很有逻辑性),所以对于开发人员而言没有吃苦.问题在于微软的实体框架EF让人简直痛恨至极(个人愚见),让我们浪费了大量时间…