// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #if !defined(AFX_STDAFX_H__5AFECD4B_C1BA_40D8_9CDA_150A0A3D20C6__INCLUDED_) #define AFX_STDAFX_H__5AFECD4B_C1BA_40D8_9CDA_150A0A3D20C6__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif// _MSC_VER > 1000 // TODO: reference additional headers your program requires here //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif// !defined(AFX_STDAFX_H__5AFECD4B_C1BA_40D8_9CDA_150A0A3D20C6__INCLUDED_)
// RedBlackTree.cpp : Defines the entry point for the console application. //主要参考了《算法导论》和博客http://www.cppblog.com/converse/archive/2006/10/07/13413.html //红黑树的性质: //1.每个结点或是红的或是黑的 //2.根结点是黑的 //3.每个叶结点(NULL)是黑的 //4.如果一个结点是红的,则它的两个儿子都是黑的 //5.对每个结点,从该结点到其他子孙结点的所有路径上包含相同数目的黑结点 //注意哨兵NIL和NULL不能混用,以及关于调整树时if...else的用法。 #include "stdafx.h" #include <iostream> #include <string> #include "RedBlackTree_.h" int main(int argc, char* argv[]) ...{ RedBlackTree<int>rt; rt.RBInsert(5); rt.RBInsert(34); rt.RBInsert(456); rt.RBInsert(75); rt.RBInsert(42); rt.RBDelete(34); rt.PrintTree(rt.GetNode()); return0; }